From 3601c5b8d91e6497efcc97789f98fbee17c9f2a3 Mon Sep 17 00:00:00 2001 From: Thiago Nache Carvalho Date: Fri, 4 Mar 2022 15:54:00 -0300 Subject: [PATCH] feat: Add IP Alias Range feature on compute instance module (#233) * Add new variable alias_ip_range default to empty slice in the compute_instance module to allow instances to set Google IP Alias Range * Rename variable alias_ip_range to alias_ip_ranges as per Morgante's request * Fix variable type usage * Instance template module should not be changed * Revert change in the example too * Fix param name --- modules/compute_instance/README.md | 1 + modules/compute_instance/main.tf | 7 +++++++ modules/compute_instance/variables.tf | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/modules/compute_instance/README.md b/modules/compute_instance/README.md index 7f4670cf..a2b8b3f6 100644 --- a/modules/compute_instance/README.md +++ b/modules/compute_instance/README.md @@ -17,6 +17,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm |------|-------------|------|---------|:--------:| | access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. |
list(object({
nat_ip = string
network_tier = string
}))
| `[]` | no | | add\_hostname\_suffix | Adds a suffix to the hostname | `bool` | `true` | no | +| alias\_ip\_ranges | (Optional) An array of alias IP ranges for this network interface. Can only be specified for network interfaces on subnet-mode networks. |
list(object({
ip_cidr_range = string
subnetwork_range_name = string
}))
| `[]` | no | | deletion\_protection | Enable deletion protection on this instance. Note: you must disable deletion protection before removing the resource, or the instance cannot be deleted and the Terraform run will not complete successfully. | `bool` | `false` | no | | hostname | Hostname of instances | `string` | `""` | no | | hostname\_suffix\_separator | Separator character to compose hostname when add\_hostname\_suffix is set to true. | `string` | `"-"` | no | diff --git a/modules/compute_instance/main.tf b/modules/compute_instance/main.tf index 29a7d70e..2a427140 100644 --- a/modules/compute_instance/main.tf +++ b/modules/compute_instance/main.tf @@ -67,6 +67,13 @@ resource "google_compute_instance_from_template" "compute_instance" { } } } + dynamic "alias_ip_range" { + for_each = var.alias_ip_ranges + content { + ip_cidr_range = alias_ip_range.value.ip_cidr_range + subnetwork_range_name = alias_ip_range.value.subnetwork_range_name + } + } } source_instance_template = var.instance_template diff --git a/modules/compute_instance/variables.tf b/modules/compute_instance/variables.tf index d66f0bd5..1b9623f0 100644 --- a/modules/compute_instance/variables.tf +++ b/modules/compute_instance/variables.tf @@ -86,3 +86,12 @@ variable "deletion_protection" { description = "Enable deletion protection on this instance. Note: you must disable deletion protection before removing the resource, or the instance cannot be deleted and the Terraform run will not complete successfully." default = false } + +variable "alias_ip_ranges" { + description = "(Optional) An array of alias IP ranges for this network interface. Can only be specified for network interfaces on subnet-mode networks." + type = list(object({ + ip_cidr_range = string + subnetwork_range_name = string + })) + default = [] +}