首页 > 解决方案 > 通过 AWS Resource Access Manager 中的 terraform 与多个 aws 账户共享多个 DNS 域

问题描述

我正在使用 AWS Route53 解析器转发发送到内部域列表(本地)的 DNS 请求。通过terraform,我想将我创建的规则分享给公司的其他账户,所以我有以下内容:

# I create as much share endpoint as domain I have, so If I have 30 domains, I'll make 30 endpoint RAM:
resource "aws_ram_resource_share" "endpoint_share" {
  count                     = length(var.forward_domain)
  name                      = "route53-${var.forward_domain[count.index]}-share"
  allow_external_principals = false
}
# Here I share every single endpoint with all the AWS ACcount we have 
resource "aws_ram_principal_association" "endpoint_ram_principal" {
  count              = length(var.resource_share_accounts)
  principal          = var.resource_share_accounts[count.index]

  resource_share_arn = {
    for item in aws_ram_resource_share.endpoint_share[*]:
        item.arn
  }
}

最后一个块,调用第一个块的 arn 输出,它是一个列表。现在,这最后一个块不起作用,我不知道如何使用多个计数,当我运行它时,我收到以下错误:

Error: Invalid 'for' expression

line 37: Key expression is required when building an object.

知道如何进行这项工作吗?

Terraform version: 0.12.23

标签: amazon-web-servicesamazon-route53terraform-provider-aws

解决方案


在 resource_share_arn 中使用方括号,如下所示:

resource_share_arn = [
  for item in aws_ram_resource_share.endpoint_share[*]:
    item.arn
]

推荐阅读