ArticCon 2022 (continued)
modules
You can bundle up multiple resources into “modules”, substituting the values provider as variables.
our previous example becomes;
# main.tf
resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
name = var.name
ip_cidr_range = var.subnet
region = var.region
network = var.network
secondary_ip_range {
range_name = var.name_two
ip_cidr_range = var.subnet_two
}
}
It also allows setting default values.
# variables.tf
variable "region" {
type = string
default = "us-west1"
}
This is great for coming up with code re-use in the form of cookie-cutter templates.