Hello - I am trying to iterate across the AWS Organizations
data source object - and having difficulties creating a subsequent map object
My code :
data "aws_organizations_organization" "org" {}
locals {
all_accounts = { for acc in data.aws_organizations_organization.org.accounts[*] : acc.*.name => acc.*.id }
scp_iam_targets = {for acc in local.all_accounts : acc.name => acc.id if contains(local.all_accounts, "lab") }
}
This code is being ran on the Master Payer Account (MPA) of the Organizations and intention is to first create a map of all the accounts with the key being the logical name and the value being the AWS account number. Then I want to create another map parsing the local.all_accounts
variable for any keys that have the substring lab
within the key name.
I am aware the code above is incorrect, and not sure how to approach iterating each element correctly for the attribute. Any suggestions are appreciated - Thank you!