小编sar*_*net的帖子

使用依赖存储桶名称的模板设置 S3 存储桶策略时如何避免循环错误?

我有一个terraform运行时失败的文件,terraform plan我收到错误消息:

Error: Cycle: module.hosting.data.template_file.bucket_policy, module.hosting.aws_s3_bucket.website
Run Code Online (Sandbox Code Playgroud)

这是有道理的,因为存储桶指的是策略,反之亦然:

data "template_file" "bucket_policy" {
  template = file("${path.module}/policy.json")
  vars = {
    bucket = aws_s3_bucket.website.arn
  }
}

resource "aws_s3_bucket" "website" {
  bucket = "xxx-website"

  website {
    index_document = "index.html"
  }

  policy = data.template_file.bucket_policy.rendered
}
Run Code Online (Sandbox Code Playgroud)

如何避免这种双向引用?

amazon-web-services terraform terraform-template-file terraform-provider-aws

8
推荐指数
2
解决办法
715
查看次数