|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | +package workbench_test |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 9 | + |
| 10 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 11 | +) |
| 12 | + |
| 13 | +func TestAccWorkbenchInstance_shielded_config_update(t *testing.T) { |
| 14 | + t.Parallel() |
| 15 | + |
| 16 | + context := map[string]interface{}{ |
| 17 | + "random_suffix": acctest.RandString(t, 10), |
| 18 | + } |
| 19 | + |
| 20 | + acctest.VcrTest(t, resource.TestCase{ |
| 21 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 22 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 23 | + Steps: []resource.TestStep{ |
| 24 | + { |
| 25 | + Config: testAccWorkbenchInstance_shielded_config_false(context), |
| 26 | + }, |
| 27 | + { |
| 28 | + ResourceName: "google_workbench_instance.instance", |
| 29 | + ImportState: true, |
| 30 | + ImportStateVerify: true, |
| 31 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 32 | + }, |
| 33 | + { |
| 34 | + Config: testAccWorkbenchInstance_shielded_config_true(context), |
| 35 | + }, |
| 36 | + { |
| 37 | + ResourceName: "google_workbench_instance.instance", |
| 38 | + ImportState: true, |
| 39 | + ImportStateVerify: true, |
| 40 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 41 | + }, |
| 42 | + }, |
| 43 | + }) |
| 44 | +} |
| 45 | + |
| 46 | +func TestAccWorkbenchInstance_shielded_config_remove(t *testing.T) { |
| 47 | + t.Parallel() |
| 48 | + |
| 49 | + context := map[string]interface{}{ |
| 50 | + "random_suffix": acctest.RandString(t, 10), |
| 51 | + } |
| 52 | + |
| 53 | + acctest.VcrTest(t, resource.TestCase{ |
| 54 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 55 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 56 | + Steps: []resource.TestStep{ |
| 57 | + { |
| 58 | + Config: testAccWorkbenchInstance_shielded_config_true(context), |
| 59 | + }, |
| 60 | + { |
| 61 | + ResourceName: "google_workbench_instance.instance", |
| 62 | + ImportState: true, |
| 63 | + ImportStateVerify: true, |
| 64 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 65 | + }, |
| 66 | + { |
| 67 | + Config: testAccWorkbenchInstance_shielded_config_none(context), |
| 68 | + }, |
| 69 | + { |
| 70 | + ResourceName: "google_workbench_instance.instance", |
| 71 | + ImportState: true, |
| 72 | + ImportStateVerify: true, |
| 73 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }) |
| 77 | +} |
| 78 | + |
| 79 | +func TestAccWorkbenchInstance_shielded_config_double_apply(t *testing.T) { |
| 80 | + t.Parallel() |
| 81 | + |
| 82 | + context := map[string]interface{}{ |
| 83 | + "random_suffix": acctest.RandString(t, 10), |
| 84 | + } |
| 85 | + |
| 86 | + acctest.VcrTest(t, resource.TestCase{ |
| 87 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 88 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 89 | + Steps: []resource.TestStep{ |
| 90 | + { |
| 91 | + Config: testAccWorkbenchInstance_shielded_config_none(context), |
| 92 | + }, |
| 93 | + { |
| 94 | + ResourceName: "google_workbench_instance.instance", |
| 95 | + ImportState: true, |
| 96 | + ImportStateVerify: true, |
| 97 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 98 | + }, |
| 99 | + { |
| 100 | + Config: testAccWorkbenchInstance_shielded_config_none(context), |
| 101 | + }, |
| 102 | + { |
| 103 | + ResourceName: "google_workbench_instance.instance", |
| 104 | + ImportState: true, |
| 105 | + ImportStateVerify: true, |
| 106 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 107 | + }, |
| 108 | + { |
| 109 | + Config: testAccWorkbenchInstance_shielded_config_false(context), |
| 110 | + }, |
| 111 | + { |
| 112 | + ResourceName: "google_workbench_instance.instance", |
| 113 | + ImportState: true, |
| 114 | + ImportStateVerify: true, |
| 115 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 116 | + }, |
| 117 | + { |
| 118 | + Config: testAccWorkbenchInstance_shielded_config_false(context), |
| 119 | + }, |
| 120 | + { |
| 121 | + ResourceName: "google_workbench_instance.instance", |
| 122 | + ImportState: true, |
| 123 | + ImportStateVerify: true, |
| 124 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 125 | + }, |
| 126 | + { |
| 127 | + Config: testAccWorkbenchInstance_shielded_config_true(context), |
| 128 | + }, |
| 129 | + { |
| 130 | + ResourceName: "google_workbench_instance.instance", |
| 131 | + ImportState: true, |
| 132 | + ImportStateVerify: true, |
| 133 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 134 | + }, |
| 135 | + { |
| 136 | + Config: testAccWorkbenchInstance_shielded_config_true(context), |
| 137 | + }, |
| 138 | + { |
| 139 | + ResourceName: "google_workbench_instance.instance", |
| 140 | + ImportState: true, |
| 141 | + ImportStateVerify: true, |
| 142 | + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels"}, |
| 143 | + }, |
| 144 | + }, |
| 145 | + }) |
| 146 | +} |
| 147 | + |
| 148 | +func testAccWorkbenchInstance_shielded_config_true(context map[string]interface{}) string { |
| 149 | + return acctest.Nprintf(` |
| 150 | +resource "google_workbench_instance" "instance" { |
| 151 | + name = "tf-test-workbench-instance%{random_suffix}" |
| 152 | + location = "us-central1-a" |
| 153 | +
|
| 154 | + gce_setup { |
| 155 | + shielded_instance_config { |
| 156 | + enable_secure_boot = true |
| 157 | + enable_vtpm = true |
| 158 | + enable_integrity_monitoring = true |
| 159 | + } |
| 160 | + } |
| 161 | +} |
| 162 | +`, context) |
| 163 | +} |
| 164 | + |
| 165 | +func testAccWorkbenchInstance_shielded_config_false(context map[string]interface{}) string { |
| 166 | + return acctest.Nprintf(` |
| 167 | +resource "google_workbench_instance" "instance" { |
| 168 | + name = "tf-test-workbench-instance%{random_suffix}" |
| 169 | + location = "us-central1-a" |
| 170 | +
|
| 171 | + gce_setup { |
| 172 | + shielded_instance_config { |
| 173 | + enable_secure_boot = false |
| 174 | + enable_vtpm = false |
| 175 | + enable_integrity_monitoring = false |
| 176 | + } |
| 177 | + } |
| 178 | +
|
| 179 | +} |
| 180 | +`, context) |
| 181 | +} |
| 182 | + |
| 183 | +func testAccWorkbenchInstance_shielded_config_none(context map[string]interface{}) string { |
| 184 | + return acctest.Nprintf(` |
| 185 | +resource "google_workbench_instance" "instance" { |
| 186 | + name = "tf-test-workbench-instance%{random_suffix}" |
| 187 | + location = "us-central1-a" |
| 188 | +} |
| 189 | +`, context) |
| 190 | +} |
0 commit comments