github cloudposse/terraform-aws-cloudfront-cdn v2.1.0

one hour ago

✨ Features

Support trusted_key_groups per ordered_cache_behavior @finchr (#169) ## what
  • Add trusted_key_groups (list(string), default []) as a per-entry field on the ordered_cache object type in variables.tf.
  • Wire it into the ordered_cache_behavior dynamic block in main.tf, independent of the existing module-level trusted_signers.
  • Add examples/signed-media: creates a real aws_cloudfront_public_key + aws_cloudfront_key_group, then a distribution with two ordered_cache entries — /media/* sets trusted_key_groups, /api/* doesn't — to demonstrate the requirement stays scoped to the one behavior that sets it.

Fully additive. trusted_key_groups defaults to [], so every existing ordered_cache entry (and anything relying on the current global trusted_signers) behaves exactly as before.

why

  • ordered_cache_behavior currently hardcodes trusted_signers = var.trusted_signers — one module-level list, applied identically to every entry in var.ordered_cache. There's no way to require signing on just one path pattern without forcing it onto every other ordered cache behavior on the same distribution.
  • trusted_key_groups, the modern, AWS-recommended replacement for trusted_signers (which depends on legacy, account-level CloudFront key pairs), wasn't exposed on ordered_cache at all.
  • Without this, protecting one path (e.g. signed-cookie media) behind an existing distribution that also serves an unsigned path (e.g. /api/*) isn't possible — the only workaround is a second CloudFront distribution just for the signed path, with its own hostname, DNS record, certificate alias, and bucket-policy wiring.
  • Verified with a real terraform plan against examples/signed-media: the /media/* ordered_cache_behavior gets trusted_key_groups set, /api/* gets [], and default_cache_behavior is untouched either way.

references

Don't miss a new terraform-aws-cloudfront-cdn release

NewReleases is sending notifications on new releases.