From 8330553932d57cb1c915b92bbf898ea5f463f392 Mon Sep 17 00:00:00 2001 From: Fabio Santos Date: Tue, 1 Oct 2024 11:38:10 +0100 Subject: [PATCH] Add `nic_type` and `stack_type` network interfaces parameters in umig submodule --- modules/umig/README.md | 4 +++- modules/umig/main.tf | 5 ++++- modules/umig/metadata.yaml | 8 ++++++++ modules/umig/variables.tf | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/modules/umig/README.md b/modules/umig/README.md index 3cda1fa0..fb8606d9 100644 --- a/modules/umig/README.md +++ b/modules/umig/README.md @@ -16,16 +16,18 @@ 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. |
list(list(object({
nat_ip = string
network_tier = string
})))
| `[]` | no | -| additional\_networks | Additional network interface details for GCE, if any. |
list(object({
network = string
subnetwork = string
subnetwork_project = string
network_ip = string
access_config = list(object({
nat_ip = string
network_tier = string
}))
ipv6_access_config = list(object({
network_tier = string
}))
}))
| `[]` | no | +| additional\_networks | Additional network interface details for GCE, if any. |
list(object({
network = string
subnetwork = string
subnetwork_project = string
network_ip = string
nic_type = optional(string, null)
stack_type = optional(string, null)
access_config = list(object({
nat_ip = string
network_tier = string
}))
ipv6_access_config = list(object({
network_tier = string
}))
}))
| `[]` | 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 | `string` | 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. |
list(list(object({
network_tier = string
})))
| `[]` | no | | named\_ports | Named name and named port |
list(object({
name = string
port = number
}))
| `[]` | no | | network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | +| nic\_type | Valid values are "VIRTIO\_NET", "GVNIC" or set to null to accept API default behavior. | `string` | `null` | no | | num\_instances | Number of instances to create. This value is ignored if static\_ips is provided. | `string` | `"1"` | no | | project\_id | The GCP project ID | `string` | `null` | no | | region | The GCP region where the unmanaged instance group resides. | `string` | n/a | yes | +| stack\_type | The stack type for this network interface to identify whether the IPv6 feature is enabled or not. Values are `IPV4_IPV6` or `IPV4_ONLY`. Default behavior is equivalent to IPV4\_ONLY. | `string` | `null` | no | | static\_ips | List of static IPs for VM instances | `list(string)` | `[]` | no | | subnetwork | Subnet to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | | subnetwork\_project | The project that subnetwork belongs to | `string` | `""` | no | diff --git a/modules/umig/main.tf b/modules/umig/main.tf index 20265c74..7183784b 100644 --- a/modules/umig/main.tf +++ b/modules/umig/main.tf @@ -57,7 +57,8 @@ resource "google_compute_instance_from_template" "compute_instance" { subnetwork = var.subnetwork subnetwork_project = var.subnetwork_project network_ip = length(var.static_ips) == 0 ? "" : element(local.static_ips, count.index) - + nic_type = var.nic_type + stack_type = var.stack_type dynamic "access_config" { # convert to map to use lookup function with default value for_each = lookup({ for k, v in var.access_config : k => v }, count.index, []) @@ -83,6 +84,8 @@ resource "google_compute_instance_from_template" "compute_instance" { subnetwork = network_interface.value.subnetwork subnetwork_project = network_interface.value.subnetwork_project network_ip = length(network_interface.value.network_ip) > 0 ? network_interface.value.network_ip : null + nic_type = lookup(network_interface.value, "nic_type", null) + stack_type = lookup(network_interface.value, "stack_type", null) dynamic "access_config" { for_each = network_interface.value.access_config content { diff --git a/modules/umig/metadata.yaml b/modules/umig/metadata.yaml index 6ab20114..7008c112 100644 --- a/modules/umig/metadata.yaml +++ b/modules/umig/metadata.yaml @@ -94,6 +94,8 @@ spec: subnetwork = string subnetwork_project = string network_ip = string + nic_type = optional(string, null) + stack_type = optional(string, null) access_config = list(object({ nat_ip = string network_tier = string @@ -134,6 +136,9 @@ spec: description: Network to deploy to. Only one of network or subnetwork should be specified. varType: string defaultValue: "" + - name: nic_type + description: Valid values are "VIRTIO_NET", "GVNIC" or set to null to accept API default behavior. + varType: string - name: num_instances description: Number of instances to create. This value is ignored if static_ips is provided. varType: string @@ -145,6 +150,9 @@ spec: description: The GCP region where the unmanaged instance group resides. varType: string required: true + - name: stack_type + description: The stack type for this network interface to identify whether the IPv6 feature is enabled or not. Values are `IPV4_IPV6` or `IPV4_ONLY`. Default behavior is equivalent to IPV4_ONLY. + varType: string - name: static_ips description: List of static IPs for VM instances varType: list(string) diff --git a/modules/umig/variables.tf b/modules/umig/variables.tf index 4c056106..877430e3 100644 --- a/modules/umig/variables.tf +++ b/modules/umig/variables.tf @@ -43,6 +43,23 @@ variable "subnetwork_project" { default = "" } +variable "nic_type" { + description = "Valid values are \"VIRTIO_NET\", \"GVNIC\" or set to null to accept API default behavior." + type = string + default = null + + validation { + condition = var.nic_type == null || var.nic_type == "GVNIC" || var.nic_type == "VIRTIO_NET" + error_message = "The \"nic_type\" variable must be set to \"VIRTIO_NET\", \"GVNIC\", or null to allow API default selection." + } +} + +variable "stack_type" { + description = "The stack type for this network interface to identify whether the IPv6 feature is enabled or not. Values are `IPV4_IPV6` or `IPV4_ONLY`. Default behavior is equivalent to IPV4_ONLY." + type = string + default = null +} + variable "additional_networks" { description = "Additional network interface details for GCE, if any." default = [] @@ -51,6 +68,8 @@ variable "additional_networks" { subnetwork = string subnetwork_project = string network_ip = string + nic_type = optional(string, null) + stack_type = optional(string, null) access_config = list(object({ nat_ip = string network_tier = string