Here is a resource block that uses for_each
on a set of string names. Each resource ends up being an environment variable for this provider, including a key and value:
resource "environments_variables_v1" "api_env_var" {
service_sid = local.api_sid
environment_sid = local.api_env_sid
for_each = {
for k, v in var.api_env_var_names : k => v
if var.feature_flag
}
key = upper(each.value)
value = var.each.value
}
The output should be a key (name changed to uppercase) and a value. The value is coming from secrets in the environment. I have a variable declared for it:
variable "api_env_var_name_1" {
default = ""
type = string
description = "1st environment secret."
sensitive = true
nullable = false
}
My problem is I don't see a way to take an each.value
and use it as the key name for a variable. var.each.value
above is not the right syntax but I don't see an alternative.