In the previous lab, I created a reusable Terraform module for Google Cloud networking.
That module created:
a custom VPC network
multiple subnets
firewall rules
outputs for network, subnet, and firewall information
That was already an improvement from writing every resource directly in the root configuration.
However, the network module was still isolated. It created network resources, but nothing else was consuming those outputs yet.
So in this lab, I wanted to take the next logical step:
Create a Compute Engine VM that uses the subnet output from the network module.
At first, I considered creating the VM directly in the root module. But then I changed the format and added a second module:
modules/gcp-vm
Enter fullscreen mode
Exit fullscreen mode
So now the lab has two child modules:
modules/gcp-network modules/gcp-vm
Enter fullscreen mode
Exit fullscreen mode
The purpose of this lab is to understand module composition.
The main idea is:
The network module creates the network.…