Reputation: 117
I'm using 0.14.7 terraform version and 1.3.2 Helm provider.
I'm trying to deploy the same chart application with different values file and different namespace like totally independent applications:
resource "helm_release" "kong-deploy" {
for_each = var.country
chart = "./helm-charts/kong"
name = "kong"
namespace = "each.value.country"
create_namespace = true
version = "2.0"
timeout = 60
values = [
file("./helm-values/${local.environment}/kong-${local.environment}-${each.value.country}.yaml")
]
}
And here are the tfvars:
country = {
spain = "es"
united_kingdom = "uk"
}
The expected result is that helm-release use the kong-pre-es/uk.yml
file.
But whe I'm doing the terraform plan, I'm getting the next error:
Error: Unsupported attribute
on deploy.tf line 11, in resource "helm_release" "kong-deploy":
11: file("./helm-values/${local.environment}/kong-${local.environment}-${each.value.country}.yaml")
|----------------
| each.value is "es"
This value does not have any attributes.
Error: Unsupported attribute
on deploy.tf line 11, in resource "helm_release" "kong-deploy":
11: file("./helm-values/${local.environment}/kong-${local.environment}-${each.value.country}.yaml")
|----------------
| each.value is "uk"
I don't know where is the error.. Could you help me?
Thanks
Upvotes: 0
Views: 1521
Reputation: 28739
In this example, you are iterating over a Map with key-value pairs "spain" = "es", "united_kingdom" = "uk"
. In your scope, the temporary lambda iterator variable each.key
is assigned the current iterator's key for Map iteration, and each.value
is assigned the current iterator's value for Map iteration.
For example, in the first iteration, each.key
would be assigned spain
, and each.value
would be assigned es
.
Assuming that you want the country name in each.value.country
, then this is the key in your Map, and you would update like:
values = [file("./helm-values/${local.environment}/kong-${local.environment}-${each.key}.yaml")]
and that will resolve to a suffix of spain.yml
in the first iteration.
If instead you want the language name, then this is the value in your Map, and you would update like:
values = [file("./helm-values/${local.environment}/kong-${local.environment}-${each.value}.yaml")]
Upvotes: 2