Skip to content

Commit 1305126

Browse files
feat!: add support for PSC-I and Dynamic NICs in instance_template and MIG (#569)
1 parent 5c35394 commit 1305126

File tree

10 files changed

+315
-197
lines changed

10 files changed

+315
-197
lines changed

build/int.cloudbuild.yaml

Lines changed: 50 additions & 91 deletions
Large diffs are not rendered by default.

modules/instance_template/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
1515
|------|-------------|------|---------|:--------:|
1616
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(object({<br> nat_ip = optional(string)<br> network_tier = string<br> }))</pre> | `[]` | no |
1717
| 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> auto_delete = optional(bool, true)<br> boot = optional(bool, false)<br> device_name = optional(string)<br> disk_name = optional(string)<br> disk_size_gb = optional(number)<br> disk_type = optional(string)<br> disk_labels = optional(map(string), {})<br> interface = optional(string)<br> mode = optional(string)<br> source = optional(string)<br> source_image = optional(string)<br> source_snapshot = optional(string)<br> }))</pre> | `[]` | no |
18-
| 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> nic_type = string<br> stack_type = string<br> queue_count = number<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> alias_ip_range = list(object({<br> ip_cidr_range = string<br> subnetwork_range_name = string<br> }))<br> }))</pre> | `[]` | no |
18+
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = optional(string)<br> subnetwork = optional(string)<br> subnetwork_project = optional(string)<br> network_ip = optional(string)<br> nic_type = optional(string)<br> stack_type = optional(string)<br><br> # New Fields<br> queue_count = optional(number) # Multi-queue count (Rx/Tx)<br> network_attachment = optional(string) # Consumer link for PSC-I<br> vlan = optional(number) # VLAN tag (2-255)<br><br> # Access Config (External IPv4)<br> access_config = optional(list(object({<br> nat_ip = optional(string)<br> network_tier = optional(string) # PREMIUM or STANDARD<br> })), [])<br><br> # IPv6 Access Config (External IPv6)<br> ipv6_access_config = optional(list(object({<br> network_tier = string # Always PREMIUM for IPv6<br> })), [])<br><br> # Alias IP Ranges (Secondary ranges)<br> alias_ip_range = optional(list(object({<br> ip_cidr_range = string<br> subnetwork_range_name = optional(string)<br> })), [])<br> }))</pre> | `[]` | no |
1919
| 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 |
2020
| auto\_delete | Whether or not the boot disk should be auto-deleted | `string` | `"true"` | no |
2121
| 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 |
@@ -41,6 +41,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
4141
| min\_cpu\_platform | Specifies a minimum CPU platform. Applicable values are the friendly names of CPU platforms, such as Intel Haswell or Intel Skylake. See the complete list: https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform | `string` | `null` | no |
4242
| name\_prefix | Name prefix for the instance template | `string` | `"default-instance-template"` | no |
4343
| network | The name or self\_link of the network to attach this interface to. Use network attribute for Legacy or Auto subnetted networks and subnetwork for custom subnetted networks. | `string` | `""` | no |
44+
| network\_attachment | The self\_link of the network attachment for PSC-I connection. | `string` | `null` | no |
4445
| network\_ip | Private IP address to assign to the instance if desired. | `string` | `""` | no |
4546
| nic\_type | Valid values are "VIRTIO\_NET", "GVNIC" or set to null to accept API default behavior. | `string` | `null` | no |
4647
| on\_host\_maintenance | Instance availability Policy | `string` | `"MIGRATE"` | no |
@@ -59,17 +60,20 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
5960
| spot\_instance\_termination\_action | Action to take when Compute Engine preempts a Spot VM. | `string` | `"STOP"` | no |
6061
| 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 |
6162
| startup\_script | User startup script to run when instances spin up | `string` | `""` | no |
63+
| subnets | Optional: A map containing subnet details Used to derive the subnetwork URI if subnetwork is not provided. | <pre>list(object({<br> id = string<br> region = string<br> purpose = string<br> }))</pre> | `[]` | no |
6264
| subnetwork | The name of the subnetwork to attach this interface to. The subnetwork must exist in the same region this instance will be created in. Either network or subnetwork must be provided. | `string` | `""` | no |
6365
| subnetwork\_project | The ID of the project in which the subnetwork belongs. If it is not provided, the provider project is used. | `string` | `""` | no |
6466
| tags | Network tags, provided as a list | `list(string)` | `[]` | no |
6567
| threads\_per\_core | The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. | `number` | `null` | no |
6668
| total\_egress\_bandwidth\_tier | Egress bandwidth tier setting for supported VM families | `string` | `"DEFAULT"` | no |
69+
| vlan | The VLAN ID for the primary network interface (Dynamic NIC), must be an integer from 2 to 255. | `number` | `null` | no |
6770

6871
## Outputs
6972

7073
| Name | Description |
7174
|------|-------------|
7275
| name | Name of instance template |
76+
| network\_interface\_details | The names and VLAN tags of the template interfaces. |
7377
| self\_link | Self-link of instance template |
7478
| self\_link\_unique | Unique self-link of instance template (recommended output to use instead of self\_link) |
7579
| service\_account\_info | Service account id and email |

modules/instance_template/main.tf

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,23 @@ resource "google_compute_instance_template" "tpl" {
158158
}
159159

160160
network_interface {
161-
network = var.network
162-
subnetwork = var.subnetwork
161+
network = var.network
162+
subnetwork = (
163+
var.subnetwork != "" ? var.subnetwork :
164+
try(
165+
[
166+
for s in var.subnets : s.id
167+
if s.region == var.region && (s.purpose == "PRIVATE")
168+
][0],
169+
""
170+
)
171+
)
163172
subnetwork_project = var.subnetwork_project
164173
network_ip = length(var.network_ip) > 0 ? var.network_ip : null
165174
nic_type = var.nic_type
166175
stack_type = var.stack_type
176+
vlan = var.vlan
177+
network_attachment = var.network_attachment
167178
dynamic "access_config" {
168179
for_each = var.access_config
169180
content {
@@ -192,9 +203,11 @@ resource "google_compute_instance_template" "tpl" {
192203
network = network_interface.value.network
193204
subnetwork = network_interface.value.subnetwork
194205
subnetwork_project = network_interface.value.subnetwork_project
195-
network_ip = length(network_interface.value.network_ip) > 0 ? network_interface.value.network_ip : null
206+
network_ip = try(length(network_interface.value.network_ip), 0) > 0 ? network_interface.value.network_ip : null
196207
nic_type = network_interface.value.nic_type
197208
stack_type = network_interface.value.stack_type
209+
network_attachment = network_interface.value.network_attachment
210+
vlan = network_interface.value.vlan
198211
queue_count = network_interface.value.queue_count
199212
dynamic "access_config" {
200213
for_each = network_interface.value.access_config

modules/instance_template/metadata.display.yaml

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ spec:
3131
access_config:
3232
name: access_config
3333
title: Access Config
34+
altDefaults:
35+
- type: ALTERNATE_TYPE_DC
36+
value:
37+
- nat_ip: null
38+
network_tier: PREMIUM
3439
properties:
3540
network_tier:
3641
name: network_tier
@@ -42,11 +47,6 @@ spec:
4247
value: STANDARD
4348
- label: FIXED_STANDARD
4449
value: FIXED_STANDARD
45-
altDefaults:
46-
- type: ALTERNATE_TYPE_DC
47-
value:
48-
- nat_ip: null
49-
network_tier: PREMIUM
5050
additional_disks:
5151
name: additional_disks
5252
title: Additional Disks
@@ -89,20 +89,41 @@ spec:
8989
name: additional_networks
9090
title: Additional Networks
9191
properties:
92+
access_config:
93+
name: access_config
94+
title: Access Config
95+
properties:
96+
network_tier:
97+
name: network_tier
98+
title: Network Tier
99+
enumValueLabels:
100+
- label: PREMIUM
101+
value: PREMIUM
102+
- label: STANDARD
103+
value: STANDARD
104+
- label: FIXED_STANDARD
105+
value: FIXED_STANDARD
106+
ipv6_access_config:
107+
name: ipv6_access_config
108+
title: Ipv6 Access Config
109+
properties:
110+
network_tier:
111+
name: network_tier
112+
title: Network Tier
113+
enumValueLabels:
114+
- label: PREMIUM
115+
value: PREMIUM
116+
- label: STANDARD
117+
value: STANDARD
92118
network:
93119
name: network
94120
title: Network
95-
regexValidation: "^(?:[a-z0-9-]{1,63}|projects/[a-z0-9-]+/global/networks/[a-z0-9-]{1,63})$"
121+
regexValidation: ^(?:[a-z0-9-]{1,63}|projects/[a-z0-9-]+/global/networks/[a-z0-9-]{1,63})$
96122
validation: Invalid network format. Must be a network name or a self link.
97-
subnetwork:
98-
name: subnetwork
99-
title: Subnetwork
100-
regexValidation: "^(?:[a-z0-9-]{1,63}|(?:projects/[a-z0-9-]+/)?(?:regions/[a-z0-9-]+/)?subnetworks/[a-z0-9-]{1,63})$"
101-
validation: Invalid subnetwork format. Must be a subnetwork name or a self link.
102123
network_ip:
103124
name: network_ip
104125
title: Network Ip
105-
regexValidation: "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
126+
regexValidation: ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
106127
validation: Invalid IP address format. Must be a valid IPv4 address.
107128
nic_type:
108129
name: nic_type
@@ -126,32 +147,11 @@ spec:
126147
value: IPV6_ONLY
127148
- label: IPV4_IPV6
128149
value: IPV4_IPV6
129-
access_config:
130-
name: access_config
131-
title: Access Config
132-
properties:
133-
network_tier:
134-
name: network_tier
135-
title: Network Tier
136-
enumValueLabels:
137-
- label: PREMIUM
138-
value: PREMIUM
139-
- label: STANDARD
140-
value: STANDARD
141-
- label: FIXED_STANDARD
142-
value: FIXED_STANDARD
143-
ipv6_access_config:
144-
name: ipv6_access_config
145-
title: Ipv6 Access Config
146-
properties:
147-
network_tier:
148-
name: network_tier
149-
title: Network Tier
150-
enumValueLabels:
151-
- label: PREMIUM
152-
value: PREMIUM
153-
- label: STANDARD
154-
value: STANDARD
150+
subnetwork:
151+
name: subnetwork
152+
title: Subnetwork
153+
regexValidation: ^(?:[a-z0-9-]{1,63}|(?:projects/[a-z0-9-]+/)?(?:regions/[a-z0-9-]+/)?subnetworks/[a-z0-9-]{1,63})$
154+
validation: Invalid subnetwork format. Must be a subnetwork name or a self link.
155155
alias_ip_range:
156156
name: alias_ip_range
157157
title: Alias Ip Range
@@ -209,7 +209,6 @@ spec:
209209
disk_type:
210210
name: disk_type
211211
title: Disk Type
212-
level: 1
213212
enumValueLabels:
214213
- label: pd-standard
215214
value: pd-standard
@@ -225,6 +224,7 @@ spec:
225224
value: hyperdisk-throughput
226225
- label: hyperdisk-extreme
227226
value: hyperdisk-extreme
227+
level: 1
228228
enable_confidential_vm:
229229
name: enable_confidential_vm
230230
title: Enable Confidential Vm
@@ -283,16 +283,19 @@ spec:
283283
network:
284284
name: network
285285
title: Network
286-
level: 1
287-
regexValidation: "^(?:[a-z0-9-]{1,63}|projects/[a-z0-9-]+/global/networks/[a-z0-9-]{1,63})$"
286+
regexValidation: ^(?:[a-z0-9-]{1,63}|projects/[a-z0-9-]+/global/networks/[a-z0-9-]{1,63})$
288287
validation: Invalid network format. Must be a network name or a self link.
288+
level: 1
289289
altDefaults:
290290
- type: ALTERNATE_TYPE_DC
291291
value: default
292+
network_attachment:
293+
name: network_attachment
294+
title: Network Attachment
292295
network_ip:
293296
name: network_ip
294297
title: Network Ip
295-
regexValidation: "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
298+
regexValidation: ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
296299
validation: Invalid IP address format. Must be a valid IPv4 address.
297300
nic_type:
298301
name: nic_type
@@ -342,7 +345,7 @@ spec:
342345
service_account_project_roles:
343346
name: service_account_project_roles
344347
title: Service Account Project Roles
345-
regexValidation: "^(roles/[a-zA-Z0-9_.]+|(projects/[a-z][a-z0-9-]{4,28}[a-z0-9]|organizations/[0-9]+)/roles/[a-zA-Z0-9_]+)$"
348+
regexValidation: ^(roles/[a-zA-Z0-9_.]+|(projects/[a-z][a-z0-9-]{4,28}[a-z0-9]|organizations/[0-9]+)/roles/[a-zA-Z0-9_]+)$
346349
validation: Role must be a valid Google Cloud IAM role name, in the format of 'roles/{role_name}'.
347350
shielded_instance_config:
348351
name: shielded_instance_config
@@ -383,12 +386,15 @@ spec:
383386
startup_script:
384387
name: startup_script
385388
title: Startup Script
389+
subnets:
390+
name: subnets
391+
title: Subnets
386392
subnetwork:
387393
name: subnetwork
388394
title: Subnetwork
389-
level: 1
390-
regexValidation: "^(?:[a-z0-9-]{1,63}|(?:projects/[a-z0-9-]+/)?(?:regions/[a-z0-9-]+/)?subnetworks/[a-z0-9-]{1,63})$"
395+
regexValidation: ^(?:[a-z0-9-]{1,63}|(?:projects/[a-z0-9-]+/)?(?:regions/[a-z0-9-]+/)?subnetworks/[a-z0-9-]{1,63})$
391396
validation: Invalid subnetwork format. Must be a subnetwork name or a self link.
397+
level: 1
392398
subnetwork_project:
393399
name: subnetwork_project
394400
title: Subnetwork Project
@@ -407,3 +413,10 @@ spec:
407413
value: DEFAULT
408414
- label: TIER_1
409415
value: TIER_1
416+
vlan:
417+
name: vlan
418+
title: Vlan
419+
runtime:
420+
outputs:
421+
network_interface_details:
422+
visibility: VISIBILITY_ROOT

0 commit comments

Comments
 (0)