cloudposse / terraform-aws-cloudfront-cdn

Terraform Module that implements a CloudFront Distribution (CDN) for a custom origin.
https://cloudposse.com/accelerate
Apache License 2.0
99 stars 121 forks source link

Add support for CloudFront Response Headers Policy #75

Open itschrishudson opened 2 years ago

itschrishudson commented 2 years ago

Describe the Feature

AWS CloudFront now supports custom response headers natively without having to set these at origin or set via Lambda.

https://aws.amazon.com/about-aws/whats-new/2021/11/amazon-cloudfront-supports-cors-security-custom-http-response-headers/

This was added to the Hashicorp AWS Provider in 3.64.0 https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_response_headers_policy

Please add support for these new data objects within the CDN module, (feature request also created for terraform-aws-cloudfront-s3-cdn)

Expected Behavior

When specified the module will allow passing appropriate config maps to create request header policies in a CloudFront distribution.

Use Case

Users of AWS CloudFront may require setting of request headers for security, caching or other purposes. This has previously required these headers to be set at the origin, or an additional lambda to set these headers. AWS has now enabled this to be set as part of the CloudFront distribution configuration.

Describe Ideal Solution

Additional map(s) similar to the ordered_cache attribute that allows the appropriate config for a CORS, custom or security header policy to be provided.

Alternatives Considered

As described earlier, setting the request header at the origin, or creating an additional lambda. For some use cases both of these approaches may not be possible for various reasons.