我有两个入口点:s3 和 do_something。s3 是 do_something 的依赖项,具有以下代码:
terragrunt.hcl
aws_regions = [ "us-east-1", "eu-east-1" ]
inputs = {
build_bucket = {
"${local.aws_regions[0]}" = {
name = "somename-${local.aws_regions[0]}"
}
"${local.aws_regions[1]}" = {
name = "somename-${local.aws_regions[1]}"
}
}
}
主文件
resource "aws_s3_bucket" "build_bucket" {
for_each = var.build_bucket
bucket = each.value["name"]
acl = "private"
}
output "build_bucket" {
value = aws_s3_bucket.build_bucket[*]
}
--terragrunt-debug 看起来像:
"build_bucket": [
[
{
"eu-east-1": {
"acceleration_status": "",
"acl": "private",
"arn": "arn:aws:s3:::somename-eu-east-1",
"bucket": "somename-eu-east-1",
},
"us-east-1": {
"acceleration_status": "",
"acl": "private",
"arn": "arn:aws:s3:::somename-us-east-1",
"bucket": "somename-us-east-1",
}
}
]
],
在 do_something 文件夹中,我有 terragrunt.hcl:
dependency "s3" {
config_path = "../s3"
}
inputs = {
build_bucket = [dependency.s3-build.outputs.build_bucket]
}
变量.tf
variable "build_bucket" {
description = "S3 buckets"
type = list
}
如何获取 build_bucket 的每个元素?
这没有用:
var.build_bucket[0].[data.aws_region.current.name].bucket