我有一个terraform
在运行时失败的文件,terraform plan
并且出现错误:
Error: Cycle: module.hosting.data.template_file.bucket_policy, module.hosting.aws_s3_bucket.website
这是有道理的,因为存储桶引用了策略,反之亦然:
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
}
如何避免这种双向引用?
您可以自己构建存储桶的ARN:
locals {
bucket_name = "example"
bucket_arn = "arn:aws:s3:::${local.bucket_name}"
}
data "template_file" "bucket_policy" {
template = file("${path.module}/policy.json")
vars = {
bucket = local.bucket_arn
}
}
resource "aws_s3_bucket" "website" {
bucket = local.bucket_name
website {
index_document = "index.html"
}
policy = data.template_file.bucket_policy.rendered
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句