Skip to content

Commit 3601c5b

Browse files
authored
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
1 parent ec31f2f commit 3601c5b

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

modules/compute_instance/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
1717
|------|-------------|------|---------|:--------:|
1818
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(object({<br> nat_ip = string<br> network_tier = string<br> }))</pre> | `[]` | no |
1919
| add\_hostname\_suffix | Adds a suffix to the hostname | `bool` | `true` | no |
20+
| 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. | <pre>list(object({<br> ip_cidr_range = string<br> subnetwork_range_name = string<br> }))</pre> | `[]` | no |
2021
| 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 |
2122
| hostname | Hostname of instances | `string` | `""` | no |
2223
| hostname\_suffix\_separator | Separator character to compose hostname when add\_hostname\_suffix is set to true. | `string` | `"-"` | no |

modules/compute_instance/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ resource "google_compute_instance_from_template" "compute_instance" {
6767
}
6868
}
6969
}
70+
dynamic "alias_ip_range" {
71+
for_each = var.alias_ip_ranges
72+
content {
73+
ip_cidr_range = alias_ip_range.value.ip_cidr_range
74+
subnetwork_range_name = alias_ip_range.value.subnetwork_range_name
75+
}
76+
}
7077
}
7178

7279
source_instance_template = var.instance_template

modules/compute_instance/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ variable "deletion_protection" {
8686
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."
8787
default = false
8888
}
89+
90+
variable "alias_ip_ranges" {
91+
description = "(Optional) An array of alias IP ranges for this network interface. Can only be specified for network interfaces on subnet-mode networks."
92+
type = list(object({
93+
ip_cidr_range = string
94+
subnetwork_range_name = string
95+
}))
96+
default = []
97+
}

0 commit comments

Comments
 (0)