terraform-provider-azurerm icon indicating copy to clipboard operation
terraform-provider-azurerm copied to clipboard

azurerm_storage_blob - infer content type from file extension

Open colincoleman opened this issue 8 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Community Note

  • Please vote on this issue by adding a :thumbsup: reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Description

When creating azure_storage_blob resources the content type must be manually set or it defaults to application/octet-stream It would be nice if the default behaviour was to default to the mime type based on the file extension and be able to override it.

I am currently using the following lookup based work around to get around this.

locals {
  mime_types = jsondecode(file("${path.module}/mime.json"))
}

resource "azurerm_storage_blob" "blob" {
  for_each               = fileset("${path.module}/files/", "**")
  name                   = each.key
  storage_account_name   = azurerm_storage_account.static_site.name
  storage_container_name = "$web"
  type                   = "Block"
  source                 = "${path.module}/files/${each.key}"
  content_type           = lookup(local.mime_types, regex("[^.]+$", each.value), null)
  content_md5            = filemd5("${path.module}/files/${each.key}")
}

mime.json

{
  "123": "application/vnd.lotus-1-2-3",
  "1km": "application/vnd.1000minds.decision-model+xml",
  "3dml": "text/vnd.in3d.3dml",
  "3ds": "image/x-3ds",
  "3g2": "video/3gpp2",
  "3gp": "video/3gpp",
  "3gpp": "video/3gpp",
  "3mf": "model/3mf",
  "7z": "application/x-7z-compressed",
  "aab": "application/x-authorware-bin",
  "aac": "audio/x-aac"
...
}

New or Affected Resource(s)/Data Source(s)

azurerm_storage_blob

Potential Terraform Configuration

No response

References

No response

colincoleman avatar Jun 27 '24 10:06 colincoleman