gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:24:54 25 4
gpt4 key购买 nike

给定一个账户名,是否可以从中提取账户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"
}
]

最佳答案

万一其他人偶然发现了这个问题,我可以通过以下方式解决:

data "aws_organizations_organization" "main" {}

locals {
account-name = "account1"
account-index = index(data.aws_organizations_organization.main.accounts[*].name, local.account-name)
account-id = data.aws_organizations_organization.main.accounts[local.account-index].id
}

output "account_id" {
value = local.account-id
}

关于Terraform 从 aws_organizations_organization.main.accounts 中提取账户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57469195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com