Skip to content

Commit 61ba9bf

Browse files
feat: mig labels & most disruptive update policy action update (#381)
Co-authored-by: Awais Malik <[email protected]>
1 parent f6ebf2c commit 61ba9bf

File tree

18 files changed

+150
-139
lines changed

18 files changed

+150
-139
lines changed

autogen/main.tf.tmpl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,23 @@ resource "google_compute_region_instance_group_manager" "{{ module_name }}" {
108108
dynamic "update_policy" {
109109
for_each = var.update_policy
110110
content {
111-
instance_redistribution_type = lookup(update_policy.value, "instance_redistribution_type", null)
112-
max_surge_fixed = lookup(update_policy.value, "max_surge_fixed", null)
113-
max_surge_percent = lookup(update_policy.value, "max_surge_percent", null)
114-
max_unavailable_fixed = lookup(update_policy.value, "max_unavailable_fixed", null)
115-
max_unavailable_percent = lookup(update_policy.value, "max_unavailable_percent", null)
116-
min_ready_sec = lookup(update_policy.value, "min_ready_sec", null)
117-
replacement_method = lookup(update_policy.value, "replacement_method", null)
118-
minimal_action = update_policy.value.minimal_action
119-
type = update_policy.value.type
111+
instance_redistribution_type = lookup(update_policy.value, "instance_redistribution_type", null)
112+
max_surge_fixed = lookup(update_policy.value, "max_surge_fixed", null)
113+
max_surge_percent = lookup(update_policy.value, "max_surge_percent", null)
114+
max_unavailable_fixed = lookup(update_policy.value, "max_unavailable_fixed", null)
115+
max_unavailable_percent = lookup(update_policy.value, "max_unavailable_percent", null)
116+
min_ready_sec = lookup(update_policy.value, "min_ready_sec", null)
117+
replacement_method = lookup(update_policy.value, "replacement_method", null)
118+
most_disruptive_allowed_action = lookup(update_policy.value, "most_disruptive_allowed_action", null)
119+
minimal_action = update_policy.value.minimal_action
120+
type = update_policy.value.type
120121
}
121122
}
122123

124+
all_instances_config {
125+
labels = var.labels
126+
}
127+
123128
lifecycle {
124129
create_before_destroy = true
125130
ignore_changes = [distribution_policy_zones]

autogen/variables.tf.tmpl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,16 @@ variable "stateful_ips" {
118118
variable "update_policy" {
119119
description = "The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager#rolling_update_policy"
120120
type = list(object({
121-
max_surge_fixed = number
122-
instance_redistribution_type = string
123-
max_surge_percent = number
124-
max_unavailable_fixed = number
125-
max_unavailable_percent = number
126-
min_ready_sec = number
127-
replacement_method = string
128-
minimal_action = string
129-
type = string
121+
max_surge_fixed = number
122+
instance_redistribution_type = string
123+
max_surge_percent = number
124+
max_unavailable_fixed = number
125+
max_unavailable_percent = number
126+
min_ready_sec = number
127+
replacement_method = string
128+
minimal_action = string
129+
type = string
130+
most_disruptive_allowed_action = string
130131
}))
131132
default = []
132133
}
@@ -296,3 +297,9 @@ variable "mig_timeouts" {
296297
delete = "15m"
297298
}
298299
}
300+
301+
variable "labels" {
302+
type = map(string)
303+
description = "Labels, provided as a map"
304+
default = {}
305+
}

examples/mig/full/variables.tf

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,16 @@ variable "distribution_policy_zones" {
169169
variable "update_policy" {
170170
description = "The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager#rolling_update_policy"
171171
type = list(object({
172-
max_surge_fixed = number
173-
instance_redistribution_type = string
174-
max_surge_percent = number
175-
max_unavailable_fixed = number
176-
max_unavailable_percent = number
177-
min_ready_sec = number
178-
replacement_method = string
179-
minimal_action = string
180-
type = string
172+
max_surge_fixed = number
173+
instance_redistribution_type = string
174+
max_surge_percent = number
175+
max_unavailable_fixed = number
176+
max_unavailable_percent = number
177+
min_ready_sec = number
178+
replacement_method = string
179+
minimal_action = string
180+
type = string
181+
most_disruptive_allowed_action = string
181182
}))
182183
default = []
183184
}

examples/mig_stateful/main.tf

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ module "mig" {
6969
}]
7070

7171
update_policy = [{
72-
max_surge_fixed = 0
73-
instance_redistribution_type = "NONE"
74-
max_surge_percent = null
75-
max_unavailable_fixed = 4
76-
max_unavailable_percent = null
77-
min_ready_sec = 180
78-
replacement_method = "RECREATE"
79-
minimal_action = "REFRESH"
80-
type = "OPPORTUNISTIC"
72+
max_surge_fixed = 0
73+
instance_redistribution_type = "NONE"
74+
max_surge_percent = null
75+
max_unavailable_fixed = 4
76+
max_unavailable_percent = null
77+
min_ready_sec = 180
78+
replacement_method = "RECREATE"
79+
minimal_action = "REFRESH"
80+
type = "OPPORTUNISTIC"
81+
most_disruptive_allowed_action = "REFRESH"
8182
}]
8283
}

metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

modules/compute_disk_snapshot/metadata.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -85,17 +85,14 @@ spec:
8585
- name: name
8686
description: Name of the resource policy to create
8787
varType: string
88-
defaultValue: null
8988
required: true
9089
- name: project
9190
description: The project ID where the resources will be created
9291
varType: string
93-
defaultValue: null
9492
required: true
9593
- name: region
9694
description: Region where resource policy resides
9795
varType: string
98-
defaultValue: null
9996
required: true
10097
- name: snapshot_properties
10198
description: The properties of the schedule policy. For more details see https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_resource_policy#snapshot_properties
@@ -107,7 +104,6 @@ spec:
107104
storage_locations = list(string)
108105
}
109106
)
110-
defaultValue: null
111107
- name: snapshot_retention_policy
112108
description: The retention policy to be applied to the schedule policy. For more details see https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_resource_policy#retention_policy
113109
varType: |-
@@ -117,7 +113,6 @@ spec:
117113
on_source_disk_delete = string
118114
}
119115
)
120-
defaultValue: null
121116
required: true
122117
- name: snapshot_schedule
123118
description: The scheduled to be used by the snapshot policy. For more details see https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_resource_policy#schedule
@@ -148,7 +143,6 @@ spec:
148143
)
149144
}
150145
)
151-
defaultValue: null
152146
required: true
153147
outputs:
154148
- name: attachments

modules/compute_instance/metadata.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -109,7 +109,6 @@ spec:
109109
- name: instance_template
110110
description: Instance template self_link used to create compute instances
111111
varType: string
112-
defaultValue: null
113112
required: true
114113
- name: ipv6_access_config
115114
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.
@@ -121,7 +120,6 @@ spec:
121120
- name: labels
122121
description: (Optional) Labels to override those from the template, provided as a map
123122
varType: map(string)
124-
defaultValue: null
125123
- name: network
126124
description: Network to deploy to. Only one of network or subnetwork should be specified.
127125
varType: string
@@ -133,11 +131,9 @@ spec:
133131
- name: region
134132
description: Region where the instances should be created.
135133
varType: string
136-
defaultValue: null
137134
- name: resource_manager_tags
138135
description: (Optional) A tag is a key-value pair that can be attached to a Google Cloud resource. You can use tags to conditionally allow or deny policies based on whether a resource has a specific tag. This value is not returned by the API. In Terraform, this value cannot be updated and changing it will recreate the resource.
139136
varType: map(string)
140-
defaultValue: null
141137
- name: resource_policies
142138
description: (Optional) A list of short names or self_links of resource policies to attach to the instance. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported.
143139
varType: list(string)
@@ -157,7 +153,6 @@ spec:
157153
- name: zone
158154
description: Zone where the instances should be created. If not specified, instances will be spread across available zones in the region.
159155
varType: string
160-
defaultValue: null
161156
outputs:
162157
- name: available_zones
163158
description: List of available zones in region

modules/instance_template/metadata.yaml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -130,7 +130,6 @@ spec:
130130
ip_cidr_range = string
131131
subnetwork_range_name = string
132132
})
133-
defaultValue: null
134133
- name: auto_delete
135134
description: Whether or not the boot disk should be auto-deleted
136135
varType: string
@@ -146,7 +145,6 @@ spec:
146145
- name: disk_encryption_key
147146
description: The id of the encryption key that is stored in Google Cloud KMS to use to encrypt all the disks on this instance
148147
varType: string
149-
defaultValue: null
150148
- name: disk_labels
151149
description: Labels to be assigned to boot disk, provided as a map
152150
varType: map(string)
@@ -178,7 +176,6 @@ spec:
178176
type = string
179177
count = number
180178
})
181-
defaultValue: null
182179
- name: ipv6_access_config
183180
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.
184181
varType: |-
@@ -197,15 +194,13 @@ spec:
197194
- name: maintenance_interval
198195
description: Specifies the frequency of planned maintenance events
199196
varType: string
200-
defaultValue: null
201197
- name: metadata
202198
description: Metadata, provided as a map
203199
varType: map(string)
204200
defaultValue: {}
205201
- name: min_cpu_platform
206202
description: "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"
207203
varType: string
208-
defaultValue: null
209204
- name: name_prefix
210205
description: Name prefix for the instance template
211206
varType: string
@@ -221,7 +216,6 @@ spec:
221216
- name: nic_type
222217
description: Valid values are "VIRTIO_NET", "GVNIC" or set to null to accept API default behavior.
223218
varType: string
224-
defaultValue: null
225219
- name: on_host_maintenance
226220
description: Instance availability Policy
227221
varType: string
@@ -233,11 +227,9 @@ spec:
233227
- name: project_id
234228
description: The GCP project ID
235229
varType: string
236-
defaultValue: null
237230
- name: region
238231
description: Region where the instance template should be created.
239232
varType: string
240-
defaultValue: null
241233
- name: resource_policies
242234
description: A list of self_links of resource policies to attach to the instance. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported.
243235
varType: list(string)
@@ -249,7 +241,6 @@ spec:
249241
email = string
250242
scopes = set(string)
251243
})
252-
defaultValue: null
253244
required: true
254245
- name: shielded_instance_config
255246
description: Not used unless enable_shielded_vm is true. Shielded VM configuration for the instance.
@@ -286,7 +277,6 @@ spec:
286277
- name: stack_type
287278
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.
288279
varType: string
289-
defaultValue: null
290280
- name: startup_script
291281
description: User startup script to run when instances spin up
292282
varType: string
@@ -306,7 +296,6 @@ spec:
306296
- name: threads_per_core
307297
description: The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1.
308298
varType: number
309-
defaultValue: null
310299
- name: total_egress_bandwidth_tier
311300
description: Egress bandwidth tier setting for supported VM families
312301
varType: string

modules/mig/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The current version is 2.X. The following guides are available to assist with up
3232
| health\_check\_name | Health check name. When variable is empty, name will be derived from var.hostname. | `string` | `""` | no |
3333
| hostname | Hostname prefix for instances | `string` | `"default"` | no |
3434
| instance\_template | Instance template self\_link used to create compute instances | `string` | n/a | yes |
35+
| labels | Labels, provided as a map | `map(string)` | `{}` | no |
3536
| max\_replicas | The maximum number of instances that the autoscaler can scale up to. This is required when creating or updating an autoscaler. The maximum number of replicas should not be lower than minimal number of replicas. | `number` | `10` | no |
3637
| mig\_name | Managed instance group name. When variable is empty, name will be derived from var.hostname. | `string` | `""` | no |
3738
| mig\_timeouts | Times for creation, deleting and updating the MIG resources. Can be helpful when using wait\_for\_instances to allow a longer VM startup time. | <pre>object({<br> create = string<br> update = string<br> delete = string<br> })</pre> | <pre>{<br> "create": "5m",<br> "delete": "15m",<br> "update": "5m"<br>}</pre> | no |
@@ -44,7 +45,7 @@ The current version is 2.X. The following guides are available to assist with up
4445
| stateful\_ips | Statful IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs | <pre>list(object({<br> interface_name = string<br> delete_rule = string<br> is_external = bool<br> }))</pre> | `[]` | no |
4546
| target\_pools | The target load balancing pools to assign this group to. | `list(string)` | `[]` | no |
4647
| target\_size | The target number of running instances for this managed instance group. This value should always be explicitly set unless this resource is attached to an autoscaler, in which case it should never be set. | `number` | `1` | no |
47-
| update\_policy | The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager#rolling_update_policy | <pre>list(object({<br> max_surge_fixed = number<br> instance_redistribution_type = string<br> max_surge_percent = number<br> max_unavailable_fixed = number<br> max_unavailable_percent = number<br> min_ready_sec = number<br> replacement_method = string<br> minimal_action = string<br> type = string<br> }))</pre> | `[]` | no |
48+
| update\_policy | The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager#rolling_update_policy | <pre>list(object({<br> max_surge_fixed = number<br> instance_redistribution_type = string<br> max_surge_percent = number<br> max_unavailable_fixed = number<br> max_unavailable_percent = number<br> min_ready_sec = number<br> replacement_method = string<br> minimal_action = string<br> type = string<br> most_disruptive_allowed_action = string<br> }))</pre> | `[]` | no |
4849
| wait\_for\_instances | Whether to wait for all instances to be created/updated before returning. Note that if this is set to true and the operation does not succeed, Terraform will continue trying until it times out. | `string` | `"false"` | no |
4950

5051
## Outputs

modules/mig/main.tf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,23 @@ resource "google_compute_region_instance_group_manager" "mig" {
9292
dynamic "update_policy" {
9393
for_each = var.update_policy
9494
content {
95-
instance_redistribution_type = lookup(update_policy.value, "instance_redistribution_type", null)
96-
max_surge_fixed = lookup(update_policy.value, "max_surge_fixed", null)
97-
max_surge_percent = lookup(update_policy.value, "max_surge_percent", null)
98-
max_unavailable_fixed = lookup(update_policy.value, "max_unavailable_fixed", null)
99-
max_unavailable_percent = lookup(update_policy.value, "max_unavailable_percent", null)
100-
min_ready_sec = lookup(update_policy.value, "min_ready_sec", null)
101-
replacement_method = lookup(update_policy.value, "replacement_method", null)
102-
minimal_action = update_policy.value.minimal_action
103-
type = update_policy.value.type
95+
instance_redistribution_type = lookup(update_policy.value, "instance_redistribution_type", null)
96+
max_surge_fixed = lookup(update_policy.value, "max_surge_fixed", null)
97+
max_surge_percent = lookup(update_policy.value, "max_surge_percent", null)
98+
max_unavailable_fixed = lookup(update_policy.value, "max_unavailable_fixed", null)
99+
max_unavailable_percent = lookup(update_policy.value, "max_unavailable_percent", null)
100+
min_ready_sec = lookup(update_policy.value, "min_ready_sec", null)
101+
replacement_method = lookup(update_policy.value, "replacement_method", null)
102+
most_disruptive_allowed_action = lookup(update_policy.value, "most_disruptive_allowed_action", null)
103+
minimal_action = update_policy.value.minimal_action
104+
type = update_policy.value.type
104105
}
105106
}
106107

108+
all_instances_config {
109+
labels = var.labels
110+
}
111+
107112
lifecycle {
108113
create_before_destroy = true
109114
ignore_changes = [distribution_policy_zones]

0 commit comments

Comments
 (0)