从aws_organizations_organization.main.accounts中提取Terraform帐户ID

时间:2019-08-12 22:52:48

标签: terraform

给出帐户名,是否可以从中提取帐户ID

resource "aws_organizations_organization" "main" {
}

类似这样:

output "account_id" {
  value = "aws_organizations_organization.main.accounts[name == 'account1']"
}

account_id = 012345678901

accounts = [
  {
    "arn" = "arn:aws:organizations::012345678901:account/o-abc123/012345678901"
    "email" = "account1@email.com"
    "id" = "012345678901"
    "name" = "account1"
  },
  {
    "arn" = "arn:aws:organizations::012345678902:account/o-abc123/012345678902"
    "email" = "account2@email.com"
    "id" = "012345678902"
    "name" = "account2"
  },
  {
    "arn" = "arn:aws:organizations::012345678903:account/o-abc123/012345678903"
    "email" = "account3@email.com"
    "id" = "320413348752"
    "name" = "account3"
  }
]

2 个答案:

答案 0 :(得分:1)

理论上,如果您获得2.21.0版或更高版本,则应该能够使用新的aws_organizations_organization数据源并根据帐户名对其进行过滤。例如,尽管未经测试:

data "aws_organizations_organization" "org" {
  filter {
    name   = "name"
    values = ["account1"]
  }
}

然后在需要帐户ID的地方使用data.aws_organizations_organization.org.id

答案 1 :(得分:0)

您可以使用for (int i = 80 ; i>=5 ; i/2) { System.out.println(i); } 创建电子邮件列表。然后使用null_data_source提取帐户。

matchkeys