Skip to content

Commit

Permalink
feat!: Add support of "ipv6_access_config" param for compute instance…
Browse files Browse the repository at this point in the history
… and instance template (#284)

Co-authored-by: danielgronberg <[email protected]>
Co-authored-by: Andrew Peabody <[email protected]>
  • Loading branch information
3 people authored Dec 1, 2022
1 parent bf565b0 commit fc40db1
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 6 deletions.
1 change: 1 addition & 0 deletions modules/compute_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
| hostname | Hostname of instances | `string` | `""` | no |
| hostname\_suffix\_separator | Separator character to compose hostname when add\_hostname\_suffix is set to true. | `string` | `"-"` | no |
| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes |
| ipv6\_access\_config | IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access. | <pre>list(object({<br> network_tier = string<br> }))</pre> | `[]` | no |
| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |
| num\_instances | Number of instances to create. This value is ignored if static\_ips is provided. | `string` | `"1"` | no |
| region | Region where the instances should be created. | `string` | `null` | 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 @@ -68,6 +68,13 @@ resource "google_compute_instance_from_template" "compute_instance" {
}
}

dynamic "ipv6_access_config" {
for_each = var.ipv6_access_config
content {
network_tier = ipv6_access_config.value.network_tier
}
}

dynamic "alias_ip_range" {
for_each = var.alias_ip_ranges
content {
Expand Down
8 changes: 8 additions & 0 deletions modules/compute_instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ variable "access_config" {
default = []
}

variable "ipv6_access_config" {
description = "IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access."
type = list(object({
network_tier = string
}))
default = []
}

variable "num_instances" {
description = "Number of instances to create. This value is ignored if static_ips is provided."
default = "1"
Expand Down
2 changes: 1 addition & 1 deletion modules/compute_instance/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
terraform {
required_version = ">=0.13.0"
required_providers {
google = ">= 3.71, < 5.0"
google = ">= 3.88, < 5.0"
}
provider_meta "google" {
module_name = "blueprints/terraform/terraform-google-vm:compute_instance/v7.9.0"
Expand Down
3 changes: 2 additions & 1 deletion modules/instance_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
|------|-------------|------|---------|:--------:|
| 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 |
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name | <pre>list(object({<br> disk_name = string<br> device_name = string<br> auto_delete = bool<br> boot = bool<br> disk_size_gb = number<br> disk_type = string<br> disk_labels = map(string)<br> }))</pre> | `[]` | no |
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = string<br> subnetwork = string<br> subnetwork_project = string<br> network_ip = string<br> access_config = list(object({<br> nat_ip = string<br> network_tier = string<br> }))<br> }))</pre> | `[]` | no |
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = string<br> subnetwork = string<br> subnetwork_project = string<br> network_ip = string<br> access_config = list(object({<br> nat_ip = string<br> network_tier = string<br> }))<br> ipv6_access_config = list(object({<br> network_tier = string<br> }))<br> }))</pre> | `[]` | no |
| alias\_ip\_range | An array of alias IP ranges for this network interface. Can only be specified for network interfaces on subnet-mode networks.<br>ip\_cidr\_range: The IP CIDR range represented by this alias IP range. This IP CIDR range must belong to the specified subnetwork and cannot contain IP addresses reserved by system or used by other network interfaces. At the time of writing only a netmask (e.g. /24) may be supplied, with a CIDR format resulting in an API error.<br>subnetwork\_range\_name: The subnetwork secondary range name specifying the secondary range from which to allocate the IP CIDR range for this alias IP range. If left unspecified, the primary range of the subnetwork will be used. | <pre>object({<br> ip_cidr_range = string<br> subnetwork_range_name = string<br> })</pre> | `null` | no |
| auto\_delete | Whether or not the boot disk should be auto-deleted | `string` | `"true"` | no |
| automatic\_restart | (Optional) Specifies whether the instance should be automatically restarted if it is terminated by Compute Engine (not terminated by a user). | `bool` | `true` | no |
Expand All @@ -28,6 +28,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
| enable\_nested\_virtualization | Defines whether the instance should have nested virtualization enabled. | `bool` | `false` | no |
| enable\_shielded\_vm | Whether to enable the Shielded VM configuration on the instance. Note that the instance image must support Shielded VMs. See https://cloud.google.com/compute/docs/images | `bool` | `false` | no |
| gpu | GPU information. Type and count of GPU to attach to the instance template. See https://cloud.google.com/compute/docs/gpus more details | <pre>object({<br> type = string<br> count = number<br> })</pre> | `null` | no |
| ipv6\_access\_config | IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access. | <pre>list(object({<br> network_tier = string<br> }))</pre> | `[]` | no |
| labels | Labels, provided as a map | `map(string)` | `{}` | no |
| machine\_type | Machine type to create, e.g. n1-standard-1 | `string` | `"n1-standard-1"` | no |
| metadata | Metadata, provided as a map | `map(string)` | `{}` | no |
Expand Down
12 changes: 12 additions & 0 deletions modules/instance_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ resource "google_compute_instance_template" "tpl" {
network_tier = access_config.value.network_tier
}
}
dynamic "ipv6_access_config" {
for_each = var.ipv6_access_config
content {
network_tier = ipv6_access_config.value.network_tier
}
}
dynamic "alias_ip_range" {
for_each = local.alias_ip_range_enabled ? [var.alias_ip_range] : []
content {
Expand All @@ -139,6 +145,12 @@ resource "google_compute_instance_template" "tpl" {
network_tier = access_config.value.network_tier
}
}
dynamic "ipv6_access_config" {
for_each = network_interface.value.ipv6_access_config
content {
network_tier = ipv6_access_config.value.network_tier
}
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions modules/instance_template/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ variable "additional_networks" {
nat_ip = string
network_tier = string
}))
ipv6_access_config = list(object({
network_tier = string
}))
}))
}

Expand Down Expand Up @@ -260,6 +263,14 @@ variable "access_config" {
default = []
}

variable "ipv6_access_config" {
description = "IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access."
type = list(object({
network_tier = string
}))
default = []
}

###########################
# Guest Accelerator (GPU)
###########################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ See the [simple](../../examples/preemptible_and_regular_instance_templates/simpl
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | `string` | `"false"` | no |
| disk\_size\_gb | Boot disk size in GB | `string` | `"100"` | no |
| disk\_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | `string` | `"pd-standard"` | no |
| ipv6\_access\_config | IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access. | <pre>list(object({<br> network_tier = string<br> }))</pre> | `[]` | no |
| labels | Labels, provided as a map | `map(string)` | `{}` | no |
| machine\_type | Machine type to create, e.g. n1-standard-1 | `string` | `"n1-standard-1"` | no |
| metadata | Metadata, provided as a map | `map(string)` | `{}` | no |
Expand Down
2 changes: 2 additions & 0 deletions modules/preemptible_and_regular_instance_templates/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module "preemptible" {
subnetwork = var.subnetwork
subnetwork_project = var.subnetwork_project
access_config = var.access_config
ipv6_access_config = var.ipv6_access_config
preemptible = true
}

Expand All @@ -65,5 +66,6 @@ module "regular" {
subnetwork = var.subnetwork
subnetwork_project = var.subnetwork_project
access_config = var.access_config
ipv6_access_config = var.ipv6_access_config
preemptible = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,11 @@ variable "access_config" {
}))
default = []
}

variable "ipv6_access_config" {
description = "IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access."
type = list(object({
network_tier = string
}))
default = []
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
terraform {
required_version = ">=0.13.0"
required_providers {
google = ">= 3.71, < 5.0"
google-beta = ">= 3.71, < 5.0"
google = ">= 3.88, < 5.0"
google-beta = ">= 3.88, < 5.0"
}
provider_meta "google" {
module_name = "blueprints/terraform/terraform-google-vm:preemptible_and_regular_instance_templates/v7.9.0"
Expand Down
3 changes: 2 additions & 1 deletion modules/umig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(list(object({<br> nat_ip = string<br> network_tier = string<br> })))</pre> | `[]` | no |
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = string<br> subnetwork = string<br> subnetwork_project = string<br> network_ip = string<br> access_config = list(object({<br> nat_ip = string<br> network_tier = string<br> }))<br> }))</pre> | `[]` | no |
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = string<br> subnetwork = string<br> subnetwork_project = string<br> network_ip = string<br> access_config = list(object({<br> nat_ip = string<br> network_tier = string<br> }))<br> ipv6_access_config = list(object({<br> network_tier = string<br> }))<br> }))</pre> | `[]` | 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 |
| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes |
| ipv6\_access\_config | IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access. | <pre>list(list(object({<br> network_tier = string<br> })))</pre> | `[]` | no |
| named\_ports | Named name and named port | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | no |
| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |
| num\_instances | Number of instances to create. This value is ignored if static\_ips is provided. | `string` | `"1"` | no |
Expand Down
14 changes: 14 additions & 0 deletions modules/umig/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ resource "google_compute_instance_from_template" "compute_instance" {
network_tier = access_config.value.network_tier
}
}

dynamic "ipv6_access_config" {
# convert to map to use lookup function with default value
for_each = lookup({ for k, v in var.ipv6_access_config : k => v }, count.index, [])
content {
network_tier = ipv6_access_config.value.network_tier
}
}
}

dynamic "network_interface" {
Expand All @@ -80,6 +88,12 @@ resource "google_compute_instance_from_template" "compute_instance" {
network_tier = access_config.value.network_tier
}
}
dynamic "ipv6_access_config" {
for_each = network_interface.value.ipv6_access_config
content {
network_tier = ipv6_access_config.value.network_tier
}
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions modules/umig/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ variable "additional_networks" {
nat_ip = string
network_tier = string
}))
ipv6_access_config = list(object({
network_tier = string
}))
}))
}

Expand Down Expand Up @@ -93,6 +96,14 @@ variable "access_config" {
default = []
}

variable "ipv6_access_config" {
description = "IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access."
type = list(list(object({
network_tier = string
})))
default = []
}

variable "hostname_suffix_separator" {
type = string
description = "Separator character to compose hostname when add_hostname_suffix is set to true."
Expand Down
2 changes: 1 addition & 1 deletion modules/umig/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
terraform {
required_version = ">=0.13.0"
required_providers {
google = ">= 3.71, < 5.0"
google = ">= 3.88, < 5.0"
}
provider_meta "google" {
module_name = "blueprints/terraform/terraform-google-vm:umig/v7.9.0"
Expand Down

0 comments on commit fc40db1

Please sign in to comment.