How to get the value from another module

in my whitelist folder, I have 
locals {
   whitelist = {
    dev  : [
     qa = [
output "whitelist_output" {
  value       = local.whitelist[var.environment]
  description = "Map of <env>:<whitelist>"
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

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/ 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”= [”,”,”,

Since gcp module wants to use the data map defined in whitelist module. so, I thought i can use 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 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 in it).

Could someone point out the root cause of error? Thank you very much in advance.


Hi I figured it out. in the, variable environment has been used. In the calling module, it should not be used again.