I have this problem. I am trying to create a network and subnetworks in gcp and I am using modules to do so.
So my directory structure looks like below:
modules
network
main.tf
variables.tf
subnetworks
main.tf
variables.tf
main.tf
terraform.tfvars
variables.tf
The folders inside the module where I have put the modules as the name suggests.
And main.tf inside the network looks like this:
# module to create the subnet
resource "google_compute_network" "network" {
name = var.network_name
auto_create_subnetworks = "false"
}
And the main.tf inside the subnetworks looks like this:
resource "google_compute_subnetwork" "public-subnetwork" {
network = // how to refer the network name here?
...
}
in normal scenarios when we have a one single terraform file for every resource (when we don't use modules), it would look like this:
# create vpc
resource "google_compute_network" "kubernetes-vpc" {
name = "kubernetes-vpc"
auto_create_subnetworks = "false"
}
resource "google_compute_subnetwork" "master-sub" {
network = google_compute_network.kubernetes-vpc.name
...
}
We can directly call the google_compute_network.kubernetes-vpc.name for the value of network when creating the google_compute_subnetwork. But now since I am using modules, how can I achieve this?
Thanks.