【问题标题】:How to use the the newly introduced aws_cloudfront_cache_policy resource in terraform如何在 terraform 中使用新引入的 aws_cloudfront_cache_policy 资源
【发布时间】:2021-06-08 17:18:49
【问题描述】:

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

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

【问题讨论】:

  • 您好,我也遇到了同样的问题,您找到解决方案了吗?

标签: amazon-web-services terraform amazon-cloudfront terraform-provider-aws hcl


【解决方案1】:

这就是我使用 aws_cloudfront_cache_policy 的方式:

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

这里,cache_policy_name = Managed-CachingOptimized

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

【讨论】:

  • 您好,我尝试按名称和 id 指向数据,该数据的输出返回一个对象,每个属性都标记为 null。
  • 好的,我通过名称而不是 ID 传递了它,它正在工作......我前几天做过,但不是......也许我拼错了,谁知道,我会投票给你,谢谢!
猜你喜欢
  • 2019-03-16
  • 1970-01-01
  • 1970-01-01
  • 2020-12-09
  • 1970-01-01
  • 2023-02-08
  • 2021-09-30
  • 2021-12-11
  • 2021-09-12
相关资源
最近更新 更多