如何使用terraform中新引入的aws_cloudfront_cache_policy资源

hei*_*pei 7 amazon-web-services amazon-cloudfront terraform hcl terraform-provider-aws

terraform 最近实现了aws_cloudfront_cache_policy资源和数据源(从 aws 提供商版本0.3.28IIRC 开始)。
它最终启用了Brotli压缩,这就是我需要使用它的原因,但我不确定如何将它集成到现有的 terraform 代码库中,也是因为我不太确定 和 之间的aws_cloudfront_cache_policy关系ordered_cache_behavior

  1. 如何使用aws_cloudfront_cache_policy- 我可以将其放入我的aws_cloudfront_distribution资源中吗?
  2. 缓存策略和 之间有什么区别/关系ordered_cache_behavior

小智 9

这就是我使用 aws_cloudfront_cache_policy 的方式:

data "aws_cloudfront_cache_policy" "cache_policy" {
    name = var.cache_policy_name
}
Run Code Online (Sandbox Code Playgroud)

这里,cache_policy_name = Managed-CachingOptimized

resource "aws_cloudfront_distribution" "cfd"{
    default_cache_behavior {
        cache_policy_id = data.aws_cloudfront_cache_policy.cache_policy.id
    }
}
Run Code Online (Sandbox Code Playgroud)