How to use the the newly introduced aws_cloudfront_cache_policy resource in terraform

Viewed 1161

terraform recently implemented the aws_cloudfront_cache_policy resource and data source (beginning from aws provider verion 0.3.28 IIRC).
It finally enables Brotli compression, and this is why I need to use it, but I am unsure about how to integrate it into the existing terraform codebase, also because I am not exactly sure about the relationship between aws_cloudfront_cache_policy and ordered_cache_behavior.

  1. How to use the aws_cloudfront_cache_policy - can I just put it inside my aws_cloudfront_distribution resource?
  2. What is the difference/relation betwwen the cache policy and the ordered_cache_behavior?
1 Answers

this is how i used aws_cloudfront_cache_policy :

data "aws_cloudfront_cache_policy" "cache_policy" {
    name = var.cache_policy_name
}

here, cache_policy_name = Managed-CachingOptimized

resource "aws_cloudfront_distribution" "cfd"{
    default_cache_behavior {
        cache_policy_id = data.aws_cloudfront_cache_policy.cache_policy.id
    }
}
Related