1

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}"
}
4

1 回答 1

0

您需要将输出值作为要访问的模块内的变量传递:

module "my_vpc":
  ....

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

在您的 gke 模块上,您需要有一个vpc_id变量来接收它。

于 2019-05-28T11:22:27.813 回答