So, I have a terraform folder structure as follows:

environments
  staging
    gke
        main.tf
        terraform.tfvars
        variables.tf
    vpc
        main.tf
        terraform.tfvars
        variables.tf
    secrets.tfvars (non-versioned)
    globals.tfvars
    terraform.tfvars (terragrunt helps require secrets and globals)
modules
    vpc
        main.tf
        outputs.tf
    gke
        main.tf
        outputs.tf

The problem I have is that I don't know how to access for example the VPC module self link that I am setting as output, from the GKE module.

Every example I see has like a main.tf on the "staging" level where every module is called in the same file, so that way they can access modules output, but I don't have one (should I with my folder structure approach?)

Would by solution grab the value from remote state? I was trying to access it but it always says it doesn't find the resource:

  // Define VPC
  network = "${data.terraform_remote_state.vpc.main_vpc_self_link}"

I try to access like that this output I have in my VPC module (the module is called vpc)

// Self link to the VPC
output "main_vpc_self_link" {
  value = "${google_compute_network.main_vpc_network.self_link}"
}

1 Answers

0
Blackk On

You need to pass the output value as a variable inside the module you want to access:

module "my_vpc":
  ....

module "gke":
    source = "./modules/gke
    vpc_id = module.my_vpc.id

On your gke module, you will need to have a vpc_id variable to receive it.