0

我有两个入口点: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
4

1 回答 1

0

嵌套列表...变量设置为任何而不是字符串。

variable "build_bucket_arn" {
  description = "S3 bucket ARN for the builds"
  type = any

调用原始嵌套列表:

var.build_bucket[0][0][data.aws_region.current.name].bucket
于 2020-11-06T13:01:26.040 回答