Skip to content

Commit 1182f2f

Browse files
authored
Feature gap: Add skip_guest_os_shutdown for scheduling in instance (#15041)
Signed-off-by: Cezary Sobczak <[email protected]>
1 parent 85e5a04 commit 1182f2f

10 files changed

+271
-6
lines changed

mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.tmpl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ func expandScheduling(v interface{}) (*compute.Scheduling, error) {
190190
scheduling.GracefulShutdown = transformedGracefulShutdown
191191
scheduling.ForceSendFields = append(scheduling.ForceSendFields, "GracefulShutdown")
192192
}
193+
194+
if v, ok := original["skip_guest_os_shutdown"]; ok {
195+
scheduling.SkipGuestOsShutdown = v.(bool)
196+
scheduling.ForceSendFields = append(scheduling.ForceSendFields, "SkipGuestOsShutdown")
197+
}
193198
{{- end }}
194199
if v, ok := original["local_ssd_recovery_timeout"]; ok {
195200
transformedLocalSsdRecoveryTimeout, err := expandComputeLocalSsdRecoveryTimeout(v)
@@ -341,13 +346,13 @@ func expandGracefulShutdownMaxDuration(v interface{}) (*compute.Duration, error)
341346

342347
func flattenScheduling(resp *compute.Scheduling) []map[string]interface{} {
343348
schedulingMap := map[string]interface{}{
344-
"on_host_maintenance": resp.OnHostMaintenance,
345-
"preemptible": resp.Preemptible,
346-
"min_node_cpus": resp.MinNodeCpus,
347-
"provisioning_model": resp.ProvisioningModel,
349+
"on_host_maintenance": resp.OnHostMaintenance,
350+
"preemptible": resp.Preemptible,
351+
"min_node_cpus": resp.MinNodeCpus,
352+
"provisioning_model": resp.ProvisioningModel,
348353
"instance_termination_action": resp.InstanceTerminationAction,
349-
"availability_domain": resp.AvailabilityDomain,
350-
"termination_time": resp.TerminationTime,
354+
"availability_domain": resp.AvailabilityDomain,
355+
"termination_time": resp.TerminationTime,
351356
}
352357

353358
if resp.AutomaticRestart != nil {
@@ -363,6 +368,8 @@ func flattenScheduling(resp *compute.Scheduling) []map[string]interface{} {
363368
}
364369

365370
{{ if ne $.TargetVersionName `ga` -}}
371+
schedulingMap["skip_guest_os_shutdown"] = resp.SkipGuestOsShutdown
372+
366373
if resp.HostErrorTimeoutSeconds != 0 {
367374
schedulingMap["host_error_timeout_seconds"] = resp.HostErrorTimeoutSeconds
368375
}
@@ -852,6 +859,10 @@ func schedulingHasChangeWithoutReboot(d *schema.ResourceData) bool {
852859
return true
853860
}
854861

862+
if oScheduling["skip_guest_os_shutdown"] != newScheduling["skip_guest_os_shutdown"] {
863+
return true
864+
}
865+
855866
if hasGracefulShutdownChanged(oScheduling, newScheduling) {
856867
return true
857868
}

mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ var (
122122
"scheduling.0.maintenance_interval",
123123
"scheduling.0.host_error_timeout_seconds",
124124
"scheduling.0.graceful_shutdown",
125+
"scheduling.0.skip_guest_os_shutdown",
125126
{{- end }}
126127
"scheduling.0.local_ssd_recovery_timeout",
127128
}
@@ -1256,6 +1257,12 @@ be from 0 to 999,999,999 inclusive.`,
12561257
},
12571258
},
12581259
},
1260+
"skip_guest_os_shutdown": {
1261+
Type: schema.TypeBool,
1262+
Optional: true,
1263+
Default: false,
1264+
Description: `Default is false and there will be 120 seconds between GCE ACPI G2 Soft Off and ACPI G3 Mechanical Off for Standard VMs and 30 seconds for Spot VMs.`,
1265+
},
12591266
{{- end }}
12601267
},
12611268
},

mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
"scheduling.0.maintenance_interval",
4444
"scheduling.0.host_error_timeout_seconds",
4545
"scheduling.0.graceful_shutdown",
46+
"scheduling.0.skip_guest_os_shutdown",
4647
{{- end }}
4748
"scheduling.0.local_ssd_recovery_timeout",
4849
}
@@ -940,6 +941,12 @@ be from 0 to 999,999,999 inclusive.`,
940941
},
941942
},
942943
},
944+
"skip_guest_os_shutdown": {
945+
Type: schema.TypeBool,
946+
Optional: true,
947+
Default: false,
948+
Description: `Default is false and there will be 120 seconds between GCE ACPI G2 Soft Off and ACPI G3 Mechanical Off for Standard VMs and 30 seconds for Spot VMs.`,
949+
},
943950
{{- end }}
944951
},
945952
},

mmv1/third_party/terraform/services/compute/resource_compute_instance_template_test.go.tmpl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,40 @@ func TestAccComputeInstanceTemplate_gracefulShutdown(t *testing.T) {
20272027
},
20282028
})
20292029
}
2030+
2031+
func TestAccComputeInstanceTemplate_schedulingSkipGuestOSShutdown(t *testing.T) {
2032+
t.Parallel()
2033+
2034+
var instanceTemplate compute.InstanceTemplate
2035+
instanceName := fmt.Sprintf("tf-test-instance-%s", acctest.RandString(t, 10))
2036+
2037+
variant_1 := map[string]interface{}{
2038+
"instance_name": instanceName,
2039+
"skip_guest_os_shutdown": true,
2040+
}
2041+
2042+
acctest.VcrTest(t, resource.TestCase{
2043+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2044+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2045+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
2046+
Steps: []resource.TestStep{
2047+
{
2048+
Config: testAccComputeInstanceTemplate_schedulingSkipGuestOSShutdown(variant_1),
2049+
Check: resource.ComposeTestCheckFunc(
2050+
testAccCheckComputeInstanceTemplateExists(
2051+
t, "google_compute_instance_template.foobar", &instanceTemplate),
2052+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "scheduling.0.skip_guest_os_shutdown", "true"),
2053+
),
2054+
},
2055+
{
2056+
ResourceName: "google_compute_instance_template.foobar",
2057+
ImportState: true,
2058+
ImportStateVerify: true,
2059+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
2060+
},
2061+
},
2062+
})
2063+
}
20302064
{{- end }}
20312065

20322066
func TestUnitComputeInstanceTemplate_IpCidrRangeDiffSuppress(t *testing.T) {
@@ -5296,6 +5330,48 @@ resource "google_compute_instance_template" "foobar" {
52965330
`, context)
52975331
}
52985332

5333+
func testAccComputeInstanceTemplate_schedulingSkipGuestOSShutdown(context map[string]interface{}) string {
5334+
return acctest.Nprintf(`
5335+
data "google_compute_image" "my_image" {
5336+
family = "debian-11"
5337+
project = "debian-cloud"
5338+
}
5339+
5340+
resource "google_compute_instance_template" "foobar" {
5341+
name = "%{instance_name}"
5342+
machine_type = "e2-medium"
5343+
can_ip_forward = false
5344+
tags = ["foo", "bar"]
5345+
5346+
disk {
5347+
source_image = data.google_compute_image.my_image.self_link
5348+
auto_delete = true
5349+
boot = true
5350+
}
5351+
5352+
network_interface {
5353+
network = "default"
5354+
}
5355+
5356+
scheduling {
5357+
skip_guest_os_shutdown = %{skip_guest_os_shutdown}
5358+
}
5359+
5360+
metadata = {
5361+
foo = "bar"
5362+
}
5363+
5364+
service_account {
5365+
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
5366+
}
5367+
5368+
labels = {
5369+
my_label = "foobar"
5370+
}
5371+
}
5372+
`, context)
5373+
}
5374+
52995375
{{- end }}
53005376

53015377
func testAccComputeInstanceTemplate_keyRevocationActionType(context map[string]interface{}) string {

mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4590,6 +4590,37 @@ func TestAccComputeInstance_GracefulShutdownWithoutResetUpdate(t *testing.T) {
45904590
})
45914591
}
45924592

4593+
func TestAccComputeInstance_schedulingSkipGuestOSShutdown(t *testing.T) {
4594+
t.Parallel()
4595+
4596+
var instance compute.Instance
4597+
var instanceName = fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
4598+
4599+
acctest.VcrTest(t, resource.TestCase{
4600+
PreCheck: func() { acctest.AccTestPreCheck(t) },
4601+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
4602+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
4603+
Steps: []resource.TestStep{
4604+
{
4605+
Config: testAccComputeInstance_schedulingSkipGuestOSShutdown(instanceName),
4606+
Check: resource.ComposeTestCheckFunc(
4607+
testAccCheckComputeInstanceExists(
4608+
t, "google_compute_instance.foobar", &instance),
4609+
),
4610+
},
4611+
computeInstanceImportStep("us-central1-a", instanceName, []string{}),
4612+
{
4613+
Config: testAccComputeInstance_schedulingSkipGuestOSShutdownUpdated(instanceName),
4614+
Check: resource.ComposeTestCheckFunc(
4615+
testAccCheckComputeInstanceExists(
4616+
t, "google_compute_instance.foobar", &instance),
4617+
),
4618+
},
4619+
computeInstanceImportStep("us-central1-a", instanceName, []string{}),
4620+
},
4621+
})
4622+
}
4623+
45934624
func testAccComputeInstance_nic_securityPolicyCreateWithTwoAccessConfigs(t *testing.T) {
45944625
var instance compute.Instance
45954626
var instanceName = fmt.Sprintf("tf-test-instance-%s", acctest.RandString(t, 10))
@@ -4924,6 +4955,64 @@ resource "google_compute_instance" "foobar" {
49244955
`, context)
49254956
}
49264957

4958+
func testAccComputeInstance_schedulingSkipGuestOSShutdown(instance string) string {
4959+
return fmt.Sprintf(`
4960+
data "google_compute_image" "my_image" {
4961+
family = "debian-11"
4962+
project = "debian-cloud"
4963+
}
4964+
4965+
resource "google_compute_instance" "foobar" {
4966+
name = "%s"
4967+
machine_type = "e2-medium"
4968+
zone = "us-central1-a"
4969+
4970+
boot_disk {
4971+
initialize_params {
4972+
image = data.google_compute_image.my_image.self_link
4973+
}
4974+
}
4975+
4976+
network_interface {
4977+
network = "default"
4978+
}
4979+
4980+
scheduling {
4981+
skip_guest_os_shutdown = true
4982+
}
4983+
}
4984+
`, instance)
4985+
}
4986+
4987+
func testAccComputeInstance_schedulingSkipGuestOSShutdownUpdated(instance string) string {
4988+
return fmt.Sprintf(`
4989+
data "google_compute_image" "my_image" {
4990+
family = "debian-11"
4991+
project = "debian-cloud"
4992+
}
4993+
4994+
resource "google_compute_instance" "foobar" {
4995+
name = "%s"
4996+
machine_type = "e2-medium"
4997+
zone = "us-central1-a"
4998+
4999+
boot_disk {
5000+
initialize_params {
5001+
image = data.google_compute_image.my_image.self_link
5002+
}
5003+
}
5004+
5005+
network_interface {
5006+
network = "default"
5007+
}
5008+
5009+
scheduling {
5010+
skip_guest_os_shutdown = false
5011+
}
5012+
}
5013+
`, instance)
5014+
}
5015+
49275016
{{ end }}
49285017

49295018
func testAccCheckComputeInstanceUpdateMachineType(t *testing.T, n string) resource.TestCheckFunc {

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template.go.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,12 @@ be from 0 to 999,999,999 inclusive.`,
895895
},
896896
},
897897
},
898+
"skip_guest_os_shutdown": {
899+
Type: schema.TypeBool,
900+
Optional: true,
901+
Default: false,
902+
Description: `Default is false and there will be 120 seconds between GCE ACPI G2 Soft Off and ACPI G3 Mechanical Off for Standard VMs and 30 seconds for Spot VMs.`,
903+
},
898904
{{- end }}
899905
},
900906
},

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_test.go.tmpl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,40 @@ func TestAccComputeRegionInstanceTemplate_gracefulShutdown(t *testing.T) {
16701670
},
16711671
})
16721672
}
1673+
1674+
func TestAccComputeRegionInstanceTemplate_schedulingSkipGuestOSShutdown(t *testing.T) {
1675+
t.Parallel()
1676+
1677+
var instanceTemplate compute.InstanceTemplate
1678+
instanceName := fmt.Sprintf("tf-test-instance-%s", acctest.RandString(t, 10))
1679+
1680+
variant_1 := map[string]interface{}{
1681+
"instance_name": instanceName,
1682+
"skip_guest_os_shutdown": true,
1683+
}
1684+
1685+
acctest.VcrTest(t, resource.TestCase{
1686+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1687+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1688+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
1689+
Steps: []resource.TestStep{
1690+
{
1691+
Config: testAccComputeRegionInstanceTemplate_schedulingSkipGuestOSShutdown(variant_1),
1692+
Check: resource.ComposeTestCheckFunc(
1693+
testAccCheckComputeRegionInstanceTemplateExists(
1694+
t, "google_compute_region_instance_template.foobar", &instanceTemplate),
1695+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "scheduling.0.skip_guest_os_shutdown", "true"),
1696+
),
1697+
},
1698+
{
1699+
ResourceName: "google_compute_region_instance_template.foobar",
1700+
ImportState: true,
1701+
ImportStateVerify: true,
1702+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
1703+
},
1704+
},
1705+
})
1706+
}
16731707
{{- end }}
16741708

16751709
func TestAccComputeRegionInstanceTemplate_GuestOsFeatures(t *testing.T) {
@@ -4763,4 +4797,33 @@ resource "google_compute_region_instance_template" "foobar" {
47634797
}
47644798
`, context)
47654799
}
4800+
4801+
func testAccComputeRegionInstanceTemplate_schedulingSkipGuestOSShutdown(context map[string]interface{}) string {
4802+
return acctest.Nprintf(`
4803+
data "google_compute_image" "my_image" {
4804+
family = "debian-11"
4805+
project = "debian-cloud"
4806+
}
4807+
4808+
resource "google_compute_region_instance_template" "foobar" {
4809+
name = "%{instance_name}"
4810+
machine_type = "e2-medium"
4811+
region = "us-central1"
4812+
4813+
disk {
4814+
source_image = data.google_compute_image.my_image.self_link
4815+
auto_delete = true
4816+
boot = true
4817+
}
4818+
4819+
network_interface {
4820+
network = "default"
4821+
}
4822+
4823+
scheduling {
4824+
skip_guest_os_shutdown = %{skip_guest_os_shutdown}
4825+
}
4826+
}
4827+
`, context)
4828+
}
47664829
{{- end }}

mmv1/third_party/terraform/website/docs/r/compute_instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ specified, then this instance will have no external IPv6 Internet access. Struct
586586

587587
* `graceful_shutdown` - (Optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) Settings for the instance to perform a graceful shutdown. Structure is [documented below](#nested_graceful_shutdown).
588588

589+
* `skip_guest_os_shutdown` - (Optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) Boolean parameter. Default is false and there will be 120 seconds between GCE ACPI G2 Soft Off and ACPI G3 Mechanical Off for Standard VMs and 30 seconds for Spot VMs.
590+
589591
<a name="nested_graceful_shutdown"></a>The `graceful_shutdown` block supports:
590592

591593
* `enabled` - (Required) Opts-in for graceful shutdown.

mmv1/third_party/terraform/website/docs/r/compute_instance_template.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,8 @@ specified, then this instance will have no external IPv6 Internet access. Struct
687687

688688
* `graceful_shutdown` - (Optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) Settings for the instance to perform a graceful shutdown. Structure is [documented below](#nested_graceful_shutdown).
689689

690+
* `skip_guest_os_shutdown` - (Optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) Boolean parameter. Default is false and there will be 120 seconds between GCE ACPI G2 Soft Off and ACPI G3 Mechanical Off for Standard VMs and 30 seconds for Spot VMs.
691+
690692
<a name="nested_graceful_shutdown"></a>The `graceful_shutdown` block supports:
691693

692694
* `enabled` - (Required) Opts-in for graceful shutdown.

0 commit comments

Comments
 (0)