Skip to content

Commit b592f18

Browse files
Promote local_ssd_recovery_timeout field to GA. (#8498) (#15366)
Signed-off-by: Modular Magician <[email protected]>
1 parent ac0a2fa commit b592f18

10 files changed

+540
-3
lines changed

.changelog/8498.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:enhancement
2+
compute: added `local_ssd_recovery_timeout` field to `google_compute_instance` resource
3+
compute: added `local_ssd_recovery_timeout` field to `google_compute_instance_template` resource
4+
```

google/resource_compute_instance_from_template_test.go

+220
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,66 @@ func TestAccComputeInstanceFromTemplate_self_link_unique(t *testing.T) {
7070
})
7171
}
7272

73+
func TestAccComputeInstanceFromTemplate_localSsdRecoveryTimeout(t *testing.T) {
74+
t.Parallel()
75+
76+
var instance compute.Instance
77+
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
78+
templateName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
79+
resourceName := "google_compute_instance_from_template.foobar"
80+
81+
var expectedLocalSsdRecoveryTimeout = compute.Duration{}
82+
expectedLocalSsdRecoveryTimeout.Nanos = 0
83+
expectedLocalSsdRecoveryTimeout.Seconds = 3600
84+
85+
acctest.VcrTest(t, resource.TestCase{
86+
PreCheck: func() { acctest.AccTestPreCheck(t) },
87+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
88+
CheckDestroy: testAccCheckComputeInstanceFromTemplateDestroyProducer(t),
89+
Steps: []resource.TestStep{
90+
{
91+
Config: testAccComputeInstanceFromTemplate_localSsdRecoveryTimeout(instanceName, templateName),
92+
Check: resource.ComposeTestCheckFunc(
93+
testAccCheckComputeInstanceExists(t, resourceName, &instance),
94+
95+
// Check that fields were set based on the template
96+
testAccCheckComputeInstanceLocalSsdRecoveryTimeout(&instance, expectedLocalSsdRecoveryTimeout),
97+
),
98+
},
99+
},
100+
})
101+
}
102+
103+
func TestAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout(t *testing.T) {
104+
t.Parallel()
105+
106+
var instance compute.Instance
107+
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
108+
templateName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
109+
resourceName := "google_compute_instance_from_template.foobar"
110+
111+
var expectedLocalSsdRecoveryTimeout = compute.Duration{}
112+
expectedLocalSsdRecoveryTimeout.Nanos = 0
113+
expectedLocalSsdRecoveryTimeout.Seconds = 7200
114+
115+
acctest.VcrTest(t, resource.TestCase{
116+
PreCheck: func() { acctest.AccTestPreCheck(t) },
117+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
118+
CheckDestroy: testAccCheckComputeInstanceFromTemplateDestroyProducer(t),
119+
Steps: []resource.TestStep{
120+
{
121+
Config: testAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout(instanceName, templateName),
122+
Check: resource.ComposeTestCheckFunc(
123+
testAccCheckComputeInstanceExists(t, resourceName, &instance),
124+
125+
// Check that fields were set based on the template
126+
testAccCheckComputeInstanceLocalSsdRecoveryTimeout(&instance, expectedLocalSsdRecoveryTimeout),
127+
),
128+
},
129+
},
130+
})
131+
}
132+
73133
func TestAccComputeInstanceFromTemplate_overrideBootDisk(t *testing.T) {
74134
t.Parallel()
75135

@@ -341,6 +401,166 @@ resource "google_compute_instance_from_template" "foobar" {
341401
`, template, template, instance)
342402
}
343403

404+
func testAccComputeInstanceFromTemplate_localSsdRecoveryTimeout(instance, template string) string {
405+
return fmt.Sprintf(`
406+
data "google_compute_image" "my_image" {
407+
family = "debian-11"
408+
project = "debian-cloud"
409+
}
410+
411+
resource "google_compute_disk" "foobar" {
412+
name = "%s"
413+
image = data.google_compute_image.my_image.self_link
414+
size = 10
415+
type = "pd-ssd"
416+
zone = "us-central1-a"
417+
}
418+
419+
resource "google_compute_instance_template" "foobar" {
420+
name = "%s"
421+
machine_type = "n1-standard-1" // can't be e2 because of local-ssd
422+
423+
disk {
424+
source = google_compute_disk.foobar.name
425+
auto_delete = false
426+
boot = true
427+
}
428+
429+
disk {
430+
disk_type = "local-ssd"
431+
type = "SCRATCH"
432+
interface = "NVME"
433+
disk_size_gb = 375
434+
}
435+
436+
disk {
437+
source_image = data.google_compute_image.my_image.self_link
438+
auto_delete = true
439+
disk_size_gb = 100
440+
boot = false
441+
disk_type = "pd-ssd"
442+
type = "PERSISTENT"
443+
}
444+
445+
network_interface {
446+
network = "default"
447+
}
448+
449+
metadata = {
450+
foo = "bar"
451+
}
452+
453+
scheduling {
454+
automatic_restart = true
455+
local_ssd_recovery_timeout {
456+
nanos = 0
457+
seconds = 3600
458+
}
459+
}
460+
461+
can_ip_forward = true
462+
}
463+
464+
resource "google_compute_instance_from_template" "foobar" {
465+
name = "%s"
466+
zone = "us-central1-a"
467+
468+
source_instance_template = google_compute_instance_template.foobar.self_link
469+
470+
// Overrides
471+
can_ip_forward = false
472+
labels = {
473+
my_key = "my_value"
474+
}
475+
scheduling {
476+
automatic_restart = false
477+
}
478+
}
479+
`, template, template, instance)
480+
}
481+
482+
func testAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout(instance, template string) string {
483+
return fmt.Sprintf(`
484+
data "google_compute_image" "my_image" {
485+
family = "debian-11"
486+
project = "debian-cloud"
487+
}
488+
489+
resource "google_compute_disk" "foobar" {
490+
name = "%s"
491+
image = data.google_compute_image.my_image.self_link
492+
size = 10
493+
type = "pd-ssd"
494+
zone = "us-central1-a"
495+
}
496+
497+
resource "google_compute_instance_template" "foobar" {
498+
name = "%s"
499+
machine_type = "n1-standard-1" // can't be e2 because of local-ssd
500+
501+
disk {
502+
source = google_compute_disk.foobar.name
503+
auto_delete = false
504+
boot = true
505+
}
506+
507+
disk {
508+
disk_type = "local-ssd"
509+
type = "SCRATCH"
510+
interface = "NVME"
511+
disk_size_gb = 375
512+
}
513+
514+
disk {
515+
source_image = data.google_compute_image.my_image.self_link
516+
auto_delete = true
517+
disk_size_gb = 100
518+
boot = false
519+
disk_type = "pd-ssd"
520+
type = "PERSISTENT"
521+
}
522+
523+
network_interface {
524+
network = "default"
525+
}
526+
527+
metadata = {
528+
foo = "bar"
529+
}
530+
531+
scheduling {
532+
automatic_restart = true
533+
local_ssd_recovery_timeout {
534+
nanos = 0
535+
seconds = 3600
536+
}
537+
}
538+
539+
can_ip_forward = true
540+
}
541+
542+
resource "google_compute_instance_from_template" "foobar" {
543+
name = "%s"
544+
zone = "us-central1-a"
545+
546+
source_instance_template = google_compute_instance_template.foobar.self_link
547+
548+
// Overrides
549+
can_ip_forward = false
550+
labels = {
551+
my_key = "my_value"
552+
}
553+
scheduling {
554+
automatic_restart = false
555+
local_ssd_recovery_timeout {
556+
nanos = 0
557+
seconds = 7200
558+
}
559+
}
560+
}
561+
`, template, template, instance)
562+
}
563+
344564
func testAccComputeInstanceFromTemplate_self_link_unique(instance, template string) string {
345565
return fmt.Sprintf(`
346566
data "google_compute_image" "my_image" {

google/resource_compute_instance_template_test.go

+83
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package google
44

55
import (
66
"fmt"
7+
"reflect"
78
"regexp"
89
"strconv"
910
"strings"
@@ -966,6 +967,37 @@ func TestAccComputeInstanceTemplate_spot(t *testing.T) {
966967
})
967968
}
968969

970+
func TestAccComputeInstanceTemplate_localSsdRecoveryTimeout(t *testing.T) {
971+
t.Parallel()
972+
973+
var instanceTemplate compute.InstanceTemplate
974+
var expectedLocalSsdRecoveryTimeout = compute.Duration{}
975+
expectedLocalSsdRecoveryTimeout.Nanos = 0
976+
expectedLocalSsdRecoveryTimeout.Seconds = 3600
977+
978+
acctest.VcrTest(t, resource.TestCase{
979+
PreCheck: func() { acctest.AccTestPreCheck(t) },
980+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
981+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
982+
Steps: []resource.TestStep{
983+
{
984+
Config: testAccComputeInstanceTemplate_localSsdRecoveryTimeout(RandString(t, 10)),
985+
Check: resource.ComposeTestCheckFunc(
986+
testAccCheckComputeInstanceTemplateExists(
987+
t, "google_compute_instance_template.foobar", &instanceTemplate),
988+
testAccCheckComputeInstanceTemplateAutomaticRestart(&instanceTemplate, false),
989+
testAccCheckComputeInstanceTemplateLocalSsdRecoveryTimeout(&instanceTemplate, expectedLocalSsdRecoveryTimeout),
990+
),
991+
},
992+
{
993+
ResourceName: "google_compute_instance_template.foobar",
994+
ImportState: true,
995+
ImportStateVerify: true,
996+
},
997+
},
998+
})
999+
}
1000+
9691001
func TestAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(t *testing.T) {
9701002
t.Parallel()
9711003

@@ -1213,6 +1245,15 @@ func testAccCheckComputeInstanceTemplateInstanceTerminationAction(instanceTempla
12131245
}
12141246
}
12151247

1248+
func testAccCheckComputeInstanceTemplateLocalSsdRecoveryTimeout(instanceTemplate *compute.InstanceTemplate, instance_local_ssd_recovery_timeout_want compute.Duration) resource.TestCheckFunc {
1249+
return func(s *terraform.State) error {
1250+
if !reflect.DeepEqual(*instanceTemplate.Properties.Scheduling.LocalSsdRecoveryTimeout, instance_local_ssd_recovery_timeout_want) {
1251+
return fmt.Errorf("gExpected LocalSsdRecoveryTimeout: %#v; got %#v", instance_local_ssd_recovery_timeout_want, instanceTemplate.Properties.Scheduling.LocalSsdRecoveryTimeout)
1252+
}
1253+
return nil
1254+
}
1255+
}
1256+
12161257
func testAccCheckComputeInstanceTemplateAutomaticRestart(instanceTemplate *compute.InstanceTemplate, automaticRestart bool) resource.TestCheckFunc {
12171258
return func(s *terraform.State) error {
12181259
ar := instanceTemplate.Properties.Scheduling.AutomaticRestart
@@ -2932,6 +2973,48 @@ resource "google_compute_instance_template" "foobar" {
29322973
`, suffix)
29332974
}
29342975

2976+
func testAccComputeInstanceTemplate_localSsdRecoveryTimeout(suffix string) string {
2977+
return fmt.Sprintf(`
2978+
data "google_compute_image" "my_image" {
2979+
family = "debian-11"
2980+
project = "debian-cloud"
2981+
}
2982+
2983+
resource "google_compute_instance_template" "foobar" {
2984+
name = "tf-test-instance-template-%s"
2985+
machine_type = "e2-medium"
2986+
can_ip_forward = false
2987+
tags = ["foo", "bar"]
2988+
2989+
disk {
2990+
source_image = data.google_compute_image.my_image.self_link
2991+
auto_delete = true
2992+
boot = true
2993+
}
2994+
2995+
network_interface {
2996+
network = "default"
2997+
}
2998+
2999+
scheduling {
3000+
automatic_restart = false
3001+
local_ssd_recovery_timeout {
3002+
nanos = 0
3003+
seconds = 3600
3004+
}
3005+
}
3006+
3007+
metadata = {
3008+
foo = "bar"
3009+
}
3010+
3011+
service_account {
3012+
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
3013+
}
3014+
}
3015+
`, suffix)
3016+
}
3017+
29353018
func testAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(context map[string]interface{}) string {
29363019
return acctest.Nprintf(`
29373020
data "google_kms_key_ring" "ring" {

0 commit comments

Comments
 (0)