I am trying to create env variables on terraform cloud by looping through the map of variables for different accounts. I am stuck how to loop through the second map and create the variables. I expect it creates 10 variables byt appending the account id in the variables.
I tried to convert the map to a list but not able to convert the internal map
Is there any other simpler method ?
variable customSettings {
default = [
{
"awsAccountId" : "0123456789",
"roleName" : "role-tfc"
},
{
"awsAccountId" : "9876543210",
"roleName" : "role-tfe"
},
]
}
locals { // Locals for thee variables in the variable sets
Envvars = {
TFC_VAULT_RUN_ROLE = {
envvalue = "tfc-role"
description = "The name of the Vault role to authenticate against. Created role, with jwt auth"
}
TFC_VAULT_PROVIDER_AUTH = {
envvalue = true
description = "used by Aws Vault provider"
}
TFC_VAULT_BACKED_AWS_MOUNT_PATH = {
envvalue = "aws-tfc"
description = "mountpath in vault"
}
TFC_VAULT_BACKED_AWS_AUTH = {
envvalue = true
description = "Using aws vault backend"
}
TFC_VAULT_BACKED_AWS_AUTH_TYPE = {
envvalue = "assumed_role"
description = "how vault gets the aws creds"
}
}
}
locals {
getv = length(var.customSettings) > 1 ? {
for idx, acct in var.customSettings:
idx => { for r, i in local.Envvars:
r =>"${r}_tfc_${acct.awsAccountId}"
}
}:{}
}
resource "tfe_variable" "VaultBackedawsRole" {
# #count = length((local.getv))
for_each = {for idx,s in local.getv : idx => s}
}