Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

MaximilianoAguirre
Copy link

@MaximilianoAguirre MaximilianoAguirre commented Aug 11, 2023

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?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects

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"
}
  • I have executed pre-commit run -a on my pull request

Signed-off-by: Maximiliano Aguirre <[email protected]>
Signed-off-by: Maximiliano Aguirre <[email protected]>
Signed-off-by: Maximiliano Aguirre <[email protected]>
Signed-off-by: Maximiliano Aguirre <[email protected]>
@MaximilianoAguirre MaximilianoAguirre changed the title Detection of content type feat: detection of content type Aug 11, 2023
@MaximilianoAguirre MaximilianoAguirre changed the title feat: detection of content type feat: Detection of content type Aug 11, 2023
@MaximilianoAguirre MaximilianoAguirre changed the title feat: Detection of content type feat(object module): Detection of content type Aug 11, 2023
@github-actions
Copy link

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 github-actions bot added the stale label Sep 11, 2023
@github-actions
Copy link

This PR was automatically closed because of stale in 10 days

@github-actions github-actions bot closed this Sep 22, 2023
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant