Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote local_ssd_recovery_timeout field to GA. #15366

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/8498.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
compute: added `local_ssd_recovery_timeout` field to `google_compute_instance` resource
compute: added `local_ssd_recovery_timeout` field to `google_compute_instance_template` resource
```
220 changes: 220 additions & 0 deletions google/resource_compute_instance_from_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,66 @@ func TestAccComputeInstanceFromTemplate_self_link_unique(t *testing.T) {
})
}

func TestAccComputeInstanceFromTemplate_localSsdRecoveryTimeout(t *testing.T) {
t.Parallel()

var instance compute.Instance
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
templateName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
resourceName := "google_compute_instance_from_template.foobar"

var expectedLocalSsdRecoveryTimeout = compute.Duration{}
expectedLocalSsdRecoveryTimeout.Nanos = 0
expectedLocalSsdRecoveryTimeout.Seconds = 3600

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceFromTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceFromTemplate_localSsdRecoveryTimeout(instanceName, templateName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(t, resourceName, &instance),

// Check that fields were set based on the template
testAccCheckComputeInstanceLocalSsdRecoveryTimeout(&instance, expectedLocalSsdRecoveryTimeout),
),
},
},
})
}

func TestAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout(t *testing.T) {
t.Parallel()

var instance compute.Instance
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
templateName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
resourceName := "google_compute_instance_from_template.foobar"

var expectedLocalSsdRecoveryTimeout = compute.Duration{}
expectedLocalSsdRecoveryTimeout.Nanos = 0
expectedLocalSsdRecoveryTimeout.Seconds = 7200

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceFromTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout(instanceName, templateName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(t, resourceName, &instance),

// Check that fields were set based on the template
testAccCheckComputeInstanceLocalSsdRecoveryTimeout(&instance, expectedLocalSsdRecoveryTimeout),
),
},
},
})
}

func TestAccComputeInstanceFromTemplate_overrideBootDisk(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -341,6 +401,166 @@ resource "google_compute_instance_from_template" "foobar" {
`, template, template, instance)
}

func testAccComputeInstanceFromTemplate_localSsdRecoveryTimeout(instance, template string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}

resource "google_compute_disk" "foobar" {
name = "%s"
image = data.google_compute_image.my_image.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}

resource "google_compute_instance_template" "foobar" {
name = "%s"
machine_type = "n1-standard-1" // can't be e2 because of local-ssd

disk {
source = google_compute_disk.foobar.name
auto_delete = false
boot = true
}

disk {
disk_type = "local-ssd"
type = "SCRATCH"
interface = "NVME"
disk_size_gb = 375
}

disk {
source_image = data.google_compute_image.my_image.self_link
auto_delete = true
disk_size_gb = 100
boot = false
disk_type = "pd-ssd"
type = "PERSISTENT"
}

network_interface {
network = "default"
}

metadata = {
foo = "bar"
}

scheduling {
automatic_restart = true
local_ssd_recovery_timeout {
nanos = 0
seconds = 3600
}
}

can_ip_forward = true
}

resource "google_compute_instance_from_template" "foobar" {
name = "%s"
zone = "us-central1-a"

source_instance_template = google_compute_instance_template.foobar.self_link

// Overrides
can_ip_forward = false
labels = {
my_key = "my_value"
}
scheduling {
automatic_restart = false
}
}
`, template, template, instance)
}

func testAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout(instance, template string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}

resource "google_compute_disk" "foobar" {
name = "%s"
image = data.google_compute_image.my_image.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}

resource "google_compute_instance_template" "foobar" {
name = "%s"
machine_type = "n1-standard-1" // can't be e2 because of local-ssd

disk {
source = google_compute_disk.foobar.name
auto_delete = false
boot = true
}

disk {
disk_type = "local-ssd"
type = "SCRATCH"
interface = "NVME"
disk_size_gb = 375
}

disk {
source_image = data.google_compute_image.my_image.self_link
auto_delete = true
disk_size_gb = 100
boot = false
disk_type = "pd-ssd"
type = "PERSISTENT"
}

network_interface {
network = "default"
}

metadata = {
foo = "bar"
}

scheduling {
automatic_restart = true
local_ssd_recovery_timeout {
nanos = 0
seconds = 3600
}
}

can_ip_forward = true
}

resource "google_compute_instance_from_template" "foobar" {
name = "%s"
zone = "us-central1-a"

source_instance_template = google_compute_instance_template.foobar.self_link

// Overrides
can_ip_forward = false
labels = {
my_key = "my_value"
}
scheduling {
automatic_restart = false
local_ssd_recovery_timeout {
nanos = 0
seconds = 7200
}
}
}
`, template, template, instance)
}

func testAccComputeInstanceFromTemplate_self_link_unique(instance, template string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down
83 changes: 83 additions & 0 deletions google/resource_compute_instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package google

import (
"fmt"
"reflect"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -966,6 +967,37 @@ func TestAccComputeInstanceTemplate_spot(t *testing.T) {
})
}

func TestAccComputeInstanceTemplate_localSsdRecoveryTimeout(t *testing.T) {
t.Parallel()

var instanceTemplate compute.InstanceTemplate
var expectedLocalSsdRecoveryTimeout = compute.Duration{}
expectedLocalSsdRecoveryTimeout.Nanos = 0
expectedLocalSsdRecoveryTimeout.Seconds = 3600

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceTemplate_localSsdRecoveryTimeout(RandString(t, 10)),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(
t, "google_compute_instance_template.foobar", &instanceTemplate),
testAccCheckComputeInstanceTemplateAutomaticRestart(&instanceTemplate, false),
testAccCheckComputeInstanceTemplateLocalSsdRecoveryTimeout(&instanceTemplate, expectedLocalSsdRecoveryTimeout),
),
},
{
ResourceName: "google_compute_instance_template.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1213,6 +1245,15 @@ func testAccCheckComputeInstanceTemplateInstanceTerminationAction(instanceTempla
}
}

func testAccCheckComputeInstanceTemplateLocalSsdRecoveryTimeout(instanceTemplate *compute.InstanceTemplate, instance_local_ssd_recovery_timeout_want compute.Duration) resource.TestCheckFunc {
return func(s *terraform.State) error {
if !reflect.DeepEqual(*instanceTemplate.Properties.Scheduling.LocalSsdRecoveryTimeout, instance_local_ssd_recovery_timeout_want) {
return fmt.Errorf("gExpected LocalSsdRecoveryTimeout: %#v; got %#v", instance_local_ssd_recovery_timeout_want, instanceTemplate.Properties.Scheduling.LocalSsdRecoveryTimeout)
}
return nil
}
}

func testAccCheckComputeInstanceTemplateAutomaticRestart(instanceTemplate *compute.InstanceTemplate, automaticRestart bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
ar := instanceTemplate.Properties.Scheduling.AutomaticRestart
Expand Down Expand Up @@ -2932,6 +2973,48 @@ resource "google_compute_instance_template" "foobar" {
`, suffix)
}

func testAccComputeInstanceTemplate_localSsdRecoveryTimeout(suffix string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}

resource "google_compute_instance_template" "foobar" {
name = "tf-test-instance-template-%s"
machine_type = "e2-medium"
can_ip_forward = false
tags = ["foo", "bar"]

disk {
source_image = data.google_compute_image.my_image.self_link
auto_delete = true
boot = true
}

network_interface {
network = "default"
}

scheduling {
automatic_restart = false
local_ssd_recovery_timeout {
nanos = 0
seconds = 3600
}
}

metadata = {
foo = "bar"
}

service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}
`, suffix)
}

func testAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(context map[string]interface{}) string {
return acctest.Nprintf(`
data "google_kms_key_ring" "ring" {
Expand Down
Loading