Skip to content

Commit 2c58ee7

Browse files
Feature gap: Add skip_guest_os_shutdown for scheduling in instance (#15041) (#10729)
[upstream:1182f2f28415ff3f61bdaddcc135fd0fb50539ce] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent 925f6d8 commit 2c58ee7

11 files changed

+276
-0
lines changed

.changelog/15041.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
compute: added `scheduling.0.skip_guest_os_shutdown` field to `google_compute_instance` resource (beta)
3+
```
4+
5+
```release-note:enhancement
6+
compute: added `scheduling.0.skip_guest_os_shutdown` field to `google_compute_instance_template` resource (beta)
7+
```
8+
9+
```release-note:enhancement
10+
compute: added `scheduling.0.skip_guest_os_shutdown` field to `google_compute_region_instance_template` resource (beta)
11+
```

google-beta/services/compute/compute_instance_helpers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ func expandScheduling(v interface{}) (*compute.Scheduling, error) {
201201
scheduling.GracefulShutdown = transformedGracefulShutdown
202202
scheduling.ForceSendFields = append(scheduling.ForceSendFields, "GracefulShutdown")
203203
}
204+
205+
if v, ok := original["skip_guest_os_shutdown"]; ok {
206+
scheduling.SkipGuestOsShutdown = v.(bool)
207+
scheduling.ForceSendFields = append(scheduling.ForceSendFields, "SkipGuestOsShutdown")
208+
}
204209
if v, ok := original["local_ssd_recovery_timeout"]; ok {
205210
transformedLocalSsdRecoveryTimeout, err := expandComputeLocalSsdRecoveryTimeout(v)
206211
if err != nil {
@@ -369,6 +374,8 @@ func flattenScheduling(resp *compute.Scheduling) []map[string]interface{} {
369374
schedulingMap["on_instance_stop_action"] = flattenOnInstanceStopAction(resp.OnInstanceStopAction)
370375
}
371376

377+
schedulingMap["skip_guest_os_shutdown"] = resp.SkipGuestOsShutdown
378+
372379
if resp.HostErrorTimeoutSeconds != 0 {
373380
schedulingMap["host_error_timeout_seconds"] = resp.HostErrorTimeoutSeconds
374381
}
@@ -842,6 +849,10 @@ func schedulingHasChangeWithoutReboot(d *schema.ResourceData) bool {
842849
return true
843850
}
844851

852+
if oScheduling["skip_guest_os_shutdown"] != newScheduling["skip_guest_os_shutdown"] {
853+
return true
854+
}
855+
845856
if hasGracefulShutdownChanged(oScheduling, newScheduling) {
846857
return true
847858
}

google-beta/services/compute/resource_compute_instance.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ var (
133133
"scheduling.0.maintenance_interval",
134134
"scheduling.0.host_error_timeout_seconds",
135135
"scheduling.0.graceful_shutdown",
136+
"scheduling.0.skip_guest_os_shutdown",
136137
"scheduling.0.local_ssd_recovery_timeout",
137138
}
138139

@@ -1255,6 +1256,12 @@ be from 0 to 999,999,999 inclusive.`,
12551256
},
12561257
},
12571258
},
1259+
"skip_guest_os_shutdown": {
1260+
Type: schema.TypeBool,
1261+
Optional: true,
1262+
Default: false,
1263+
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.`,
1264+
},
12581265
},
12591266
},
12601267
},

google-beta/services/compute/resource_compute_instance_template.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var (
5353
"scheduling.0.maintenance_interval",
5454
"scheduling.0.host_error_timeout_seconds",
5555
"scheduling.0.graceful_shutdown",
56+
"scheduling.0.skip_guest_os_shutdown",
5657
"scheduling.0.local_ssd_recovery_timeout",
5758
}
5859

@@ -941,6 +942,12 @@ be from 0 to 999,999,999 inclusive.`,
941942
},
942943
},
943944
},
945+
"skip_guest_os_shutdown": {
946+
Type: schema.TypeBool,
947+
Optional: true,
948+
Default: false,
949+
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.`,
950+
},
944951
},
945952
},
946953
},

google-beta/services/compute/resource_compute_instance_template_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,40 @@ func TestAccComputeInstanceTemplate_gracefulShutdown(t *testing.T) {
20222022
})
20232023
}
20242024

2025+
func TestAccComputeInstanceTemplate_schedulingSkipGuestOSShutdown(t *testing.T) {
2026+
t.Parallel()
2027+
2028+
var instanceTemplate compute.InstanceTemplate
2029+
instanceName := fmt.Sprintf("tf-test-instance-%s", acctest.RandString(t, 10))
2030+
2031+
variant_1 := map[string]interface{}{
2032+
"instance_name": instanceName,
2033+
"skip_guest_os_shutdown": true,
2034+
}
2035+
2036+
acctest.VcrTest(t, resource.TestCase{
2037+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2038+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2039+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
2040+
Steps: []resource.TestStep{
2041+
{
2042+
Config: testAccComputeInstanceTemplate_schedulingSkipGuestOSShutdown(variant_1),
2043+
Check: resource.ComposeTestCheckFunc(
2044+
testAccCheckComputeInstanceTemplateExists(
2045+
t, "google_compute_instance_template.foobar", &instanceTemplate),
2046+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "scheduling.0.skip_guest_os_shutdown", "true"),
2047+
),
2048+
},
2049+
{
2050+
ResourceName: "google_compute_instance_template.foobar",
2051+
ImportState: true,
2052+
ImportStateVerify: true,
2053+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
2054+
},
2055+
},
2056+
})
2057+
}
2058+
20252059
func TestUnitComputeInstanceTemplate_IpCidrRangeDiffSuppress(t *testing.T) {
20262060
cases := map[string]struct {
20272061
Old, New string
@@ -5268,6 +5302,48 @@ resource "google_compute_instance_template" "foobar" {
52685302
`, context)
52695303
}
52705304

5305+
func testAccComputeInstanceTemplate_schedulingSkipGuestOSShutdown(context map[string]interface{}) string {
5306+
return acctest.Nprintf(`
5307+
data "google_compute_image" "my_image" {
5308+
family = "debian-11"
5309+
project = "debian-cloud"
5310+
}
5311+
5312+
resource "google_compute_instance_template" "foobar" {
5313+
name = "%{instance_name}"
5314+
machine_type = "e2-medium"
5315+
can_ip_forward = false
5316+
tags = ["foo", "bar"]
5317+
5318+
disk {
5319+
source_image = data.google_compute_image.my_image.self_link
5320+
auto_delete = true
5321+
boot = true
5322+
}
5323+
5324+
network_interface {
5325+
network = "default"
5326+
}
5327+
5328+
scheduling {
5329+
skip_guest_os_shutdown = %{skip_guest_os_shutdown}
5330+
}
5331+
5332+
metadata = {
5333+
foo = "bar"
5334+
}
5335+
5336+
service_account {
5337+
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
5338+
}
5339+
5340+
labels = {
5341+
my_label = "foobar"
5342+
}
5343+
}
5344+
`, context)
5345+
}
5346+
52715347
func testAccComputeInstanceTemplate_keyRevocationActionType(context map[string]interface{}) string {
52725348
return acctest.Nprintf(`
52735349
data "google_compute_image" "my_image" {

google-beta/services/compute/resource_compute_instance_test.go

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

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

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

google-beta/services/compute/resource_compute_region_instance_template.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,12 @@ be from 0 to 999,999,999 inclusive.`,
900900
},
901901
},
902902
},
903+
"skip_guest_os_shutdown": {
904+
Type: schema.TypeBool,
905+
Optional: true,
906+
Default: false,
907+
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.`,
908+
},
903909
},
904910
},
905911
},

google-beta/services/compute/resource_compute_region_instance_template_test.go

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+
func TestAccComputeRegionInstanceTemplate_schedulingSkipGuestOSShutdown(t *testing.T) {
1674+
t.Parallel()
1675+
1676+
var instanceTemplate compute.InstanceTemplate
1677+
instanceName := fmt.Sprintf("tf-test-instance-%s", acctest.RandString(t, 10))
1678+
1679+
variant_1 := map[string]interface{}{
1680+
"instance_name": instanceName,
1681+
"skip_guest_os_shutdown": true,
1682+
}
1683+
1684+
acctest.VcrTest(t, resource.TestCase{
1685+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1686+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1687+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
1688+
Steps: []resource.TestStep{
1689+
{
1690+
Config: testAccComputeRegionInstanceTemplate_schedulingSkipGuestOSShutdown(variant_1),
1691+
Check: resource.ComposeTestCheckFunc(
1692+
testAccCheckComputeRegionInstanceTemplateExists(
1693+
t, "google_compute_region_instance_template.foobar", &instanceTemplate),
1694+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "scheduling.0.skip_guest_os_shutdown", "true"),
1695+
),
1696+
},
1697+
{
1698+
ResourceName: "google_compute_region_instance_template.foobar",
1699+
ImportState: true,
1700+
ImportStateVerify: true,
1701+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
1702+
},
1703+
},
1704+
})
1705+
}
1706+
16731707
func TestAccComputeRegionInstanceTemplate_GuestOsFeatures(t *testing.T) {
16741708
t.Parallel()
16751709

@@ -4745,3 +4779,32 @@ resource "google_compute_region_instance_template" "foobar" {
47454779
}
47464780
`, context)
47474781
}
4782+
4783+
func testAccComputeRegionInstanceTemplate_schedulingSkipGuestOSShutdown(context map[string]interface{}) string {
4784+
return acctest.Nprintf(`
4785+
data "google_compute_image" "my_image" {
4786+
family = "debian-11"
4787+
project = "debian-cloud"
4788+
}
4789+
4790+
resource "google_compute_region_instance_template" "foobar" {
4791+
name = "%{instance_name}"
4792+
machine_type = "e2-medium"
4793+
region = "us-central1"
4794+
4795+
disk {
4796+
source_image = data.google_compute_image.my_image.self_link
4797+
auto_delete = true
4798+
boot = true
4799+
}
4800+
4801+
network_interface {
4802+
network = "default"
4803+
}
4804+
4805+
scheduling {
4806+
skip_guest_os_shutdown = %{skip_guest_os_shutdown}
4807+
}
4808+
}
4809+
`, context)
4810+
}

website/docs/r/compute_instance.html.markdown

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

601601
* `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).
602602

603+
* `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.
604+
603605
<a name="nested_graceful_shutdown"></a>The `graceful_shutdown` block supports:
604606

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

website/docs/r/compute_instance_template.html.markdown

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

702702
* `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).
703703

704+
* `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.
705+
704706
<a name="nested_graceful_shutdown"></a>The `graceful_shutdown` block supports:
705707

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

0 commit comments

Comments
 (0)