Skip to content

Commit

Permalink
feat: Add IP Alias Range feature on compute instance module (#233)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thiagonache authored Mar 4, 2022
1 parent ec31f2f commit 3601c5b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/compute_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <pre>list(object({<br> nat_ip = string<br> network_tier = string<br> }))</pre> | `[]` | 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. | <pre>list(object({<br> ip_cidr_range = string<br> subnetwork_range_name = string<br> }))</pre> | `[]` | 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 |
Expand Down
7 changes: 7 additions & 0 deletions modules/compute_instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions modules/compute_instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}

0 comments on commit 3601c5b

Please sign in to comment.