Hi,
in my whitelist
folder, I have
whitelist-map.tf
locals {
whitelist = {
dev : [
"dev-az-west1-test.com:443",
"dev-az-west2-test.com:443",
"dev-gcp-west1-test.io:443",
],
qa = [
"qa-az-west1-test.com:443",
"qa-az-west1-test.com:443",
"qa-gcp-west1-test.io:443",
],
}
outputs.tf
output "whitelist_output" {
value = local.whitelist[var.environment]
description = "Map of <env>:<whitelist>"
}
variables.tf
variable "environment" {
description = "Environment (`dev`, `qa`)."
type = string
validation {
condition = contains(["dev","qa"], var.environment)
error_message = "Invalid environment. Valid environments: `dev`, and `qa`."
}
}
in my another folder gcp
I have cluster.tf
module "deployment_whitelists" {
source = "../whitelists"
environment = var.environment
}
module "deployment" {
source = "../deployment"
environment = var.environment
settings = {"remote.whitelist" = module.deployment_whitelists.whitelist_output[var.environment]}
}
}
the plan output is:
Error: Invalid index
│
│ on ../../modules/cluster.tf line 62, in module "deployment":
│ 62: settings = {"remote.whitelist" = module.whitelists.whitelist_output[var.environment]}
│ ├────────────────
│ │ module.whitelists.whitelist_output is tuple with 3 elements
│ │ var.environment is "dev"
│
│ The given key does not identify an element in this collection value: a number is required.
What I want to get is ( for dev environment in this case):
settings = {“remote.whitelist”= [
“dev-az-west1-test.com:443”,
“dev-az-west2-test.com:443”,
“dev-gcp-west1-test.io:443”,
]}
Since gcp
module wants to use the data map defined in whitelist
module. so, I thought i can use outputs.tf to output this map data.
But it always gives me error. I tried different ways, the error is always like this.
I suspect that the way I was trying to get the value from output.tf is incorrect. Not quite sure what is wrong.
terraform.state seems cannot be used since these two folders are modules. the actual plan is in the another folder (with version.tf in it).
Could someone point out the root cause of error? Thank you very much in advance.
William