这是对此question的后续行动
我想使用基于aws_cloudformation_stack
的名称创建多个git branch
资源。 Git分支将用于测试CloudFormation
堆栈的不同版本,并且可以由多个工程师进行部署(因此,我需要让工程师访问远程terraform状态)。
我想确保每个部署的分支都有其堆栈,但是当分支更新代码时,堆栈将得到更新(堆栈被破坏并重新创建)
一种建议是使用for_each
创建多个资源。
为此,我可能需要将分支名称写入文件(在terraform apply
之前,然后将其读入列表变量,以便for_each
可以遍历列表。
但是,我想看看是否有更好的方法来实现这一目标?
resource "aws_cloudformation_stack" "subscriptions_sam_stack" {
for_each = toset(split(",", file("deployed_git_hashes.txt")))
name = "${var.app_name}---${var.app_env}--${each.value}"
capabilities = ["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
template_url = "https://${var.sam_bucket}.s3-${data.aws_region.current.name}.amazonaws.com/${aws_s3_bucket_object.sam_deploy_object.id}"
}
deployed_git_branches.txt
看起来像这样:
branch1, branch2, branch3