terraform-aws-modules / terraform-aws-s3-bucket

Terraform module to create AWS S3 resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/s3-bucket/aws
Apache License 2.0
526 stars 3.62k forks source link

feat(object module): Detection of content type #249

Closed MaximilianoAguirre closed 1 year ago

MaximilianoAguirre commented 1 year ago

Description

This PR implements a feature to detect the content type based in the value of the key set to the object once uploaded. It uses a mime types DB used by a JS library with great adoption which bases the definitions mainly in IANA standards. There is a local copy of the DB that can be used, and an optional variable that allows to download a DB when running terraform.

If content_type variable is set, everything is disabled.

Motivation and Context

Often when uploading s3 objects to s3 through terraform resources it is difficult to dynamically set the content type of the object, specially when iterating with fileset. Content type is quite important in certain scenarios, for example when using the bucket as a website (the Content-Type header sent in the HTTP header to the client will rely on this).

Breaking Changes

There is a new dependency of the hashicorp/http provider in order to be able to expose the on demand query of the DB feature. It is not a breaking change but a new dependency that existing environments might have conflicts with.

How Has This Been Tested?

Based in the examples/object, many of the possible combinations of variables to create an object have been successfully deployed:

module "object" {
  source = "../../modules/object"

  bucket      = module.s3_bucket.s3_bucket_id
  key         = "${random_pet.this.id}-local.md"
  file_source = "README.md"
}

module "object_without_extension" {
  source = "../../modules/object"

  bucket      = module.s3_bucket.s3_bucket_id
  key         = "${random_pet.this.id}-local"
  file_source = "README.md"
}

module "object_with_content_type" {
  source = "../../modules/object"

  bucket       = module.s3_bucket.s3_bucket_id
  key          = "${random_pet.this.id}-local"
  content_type = "plain/text"
  file_source  = "README.md"
}

module "object_with_content_type_query" {
  source = "../../modules/object"

  bucket           = module.s3_bucket.s3_bucket_id
  key              = "${random_pet.this.id}-local.md"
  query_mime_types = true
  file_source      = "README.md"
}

module "object_with_content_type_disabled" {
  source = "../../modules/object"

  bucket              = module.s3_bucket.s3_bucket_id
  key                 = "${random_pet.this.id}-local.md"
  detect_content_type = false
  file_source         = "README.md"
}
github-actions[bot] commented 1 year ago

This PR has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this PR will be closed in 10 days

github-actions[bot] commented 1 year ago

This PR was automatically closed because of stale in 10 days

github-actions[bot] commented 1 year ago

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.