Skip to content

Commit 7e7ceec

Browse files
Update suppress func for compute_disk.type and compute_instance.machineType. (#10641) (#18071)
[upstream:0175894d87e576bd69fb198b6d07c8ea19b865c6] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent b525420 commit 7e7ceec

File tree

4 files changed

+88
-12
lines changed

4 files changed

+88
-12
lines changed

google/services/compute/resource_compute_disk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ encryption key that protects this resource.`,
639639
Type: schema.TypeString,
640640
Optional: true,
641641
ForceNew: true,
642-
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
642+
DiffSuppressFunc: tpgresource.CompareResourceNames,
643643
Description: `URL of the disk type resource describing which disk type to use to
644644
create the disk. Provide this when creating the disk.`,
645645
Default: "pd-standard",

google/services/compute/resource_compute_disk_test.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,14 @@ func TestAccComputeDisk_update(t *testing.T) {
333333
t.Parallel()
334334

335335
diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
336+
diskType := "pd-ssd"
336337

337338
acctest.VcrTest(t, resource.TestCase{
338339
PreCheck: func() { acctest.AccTestPreCheck(t) },
339340
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
340341
Steps: []resource.TestStep{
341342
{
342-
Config: testAccComputeDisk_basic(diskName),
343+
Config: testAccComputeDisk_basic(diskName, diskType),
343344
},
344345
{
345346
ResourceName: "google_compute_disk.foobar",
@@ -348,7 +349,7 @@ func TestAccComputeDisk_update(t *testing.T) {
348349
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
349350
},
350351
{
351-
Config: testAccComputeDisk_updated(diskName),
352+
Config: testAccComputeDisk_updated(diskName, diskType),
352353
},
353354
{
354355
ResourceName: "google_compute_disk.foobar",
@@ -359,6 +360,30 @@ func TestAccComputeDisk_update(t *testing.T) {
359360
},
360361
})
361362
}
363+
364+
func TestAccComputeDisk_fromTypeUrl(t *testing.T) {
365+
t.Parallel()
366+
367+
diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
368+
diskType := fmt.Sprintf("projects/%s/zones/us-central1-a/diskTypes/pd-ssd", envvar.GetTestProjectFromEnv())
369+
370+
acctest.VcrTest(t, resource.TestCase{
371+
PreCheck: func() { acctest.AccTestPreCheck(t) },
372+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
373+
Steps: []resource.TestStep{
374+
{
375+
Config: testAccComputeDisk_basic(diskName, diskType),
376+
},
377+
{
378+
ResourceName: "google_compute_disk.foobar",
379+
ImportState: true,
380+
ImportStateVerify: true,
381+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
382+
},
383+
},
384+
})
385+
}
386+
362387
func TestAccComputeDisk_pdHyperDiskProvisionedIopsLifeCycle(t *testing.T) {
363388
t.Parallel()
364389

@@ -815,7 +840,7 @@ func TestAccComputeDisk_featuresUpdated(t *testing.T) {
815840
})
816841
}
817842

818-
func testAccComputeDisk_basic(diskName string) string {
843+
func testAccComputeDisk_basic(diskName string, diskType string) string {
819844
return fmt.Sprintf(`
820845
data "google_compute_image" "my_image" {
821846
family = "debian-11"
@@ -826,16 +851,16 @@ resource "google_compute_disk" "foobar" {
826851
name = "%s"
827852
image = data.google_compute_image.my_image.self_link
828853
size = 50
829-
type = "pd-ssd"
854+
type = "%s"
830855
zone = "us-central1-a"
831856
labels = {
832857
my-label = "my-label-value"
833858
}
834859
}
835-
`, diskName)
860+
`, diskName, diskType)
836861
}
837862

838-
func testAccComputeDisk_updated(diskName string) string {
863+
func testAccComputeDisk_updated(diskName string, diskType string) string {
839864
return fmt.Sprintf(`
840865
data "google_compute_image" "my_image" {
841866
family = "debian-11"
@@ -846,14 +871,14 @@ resource "google_compute_disk" "foobar" {
846871
name = "%s"
847872
image = data.google_compute_image.my_image.self_link
848873
size = 100
849-
type = "pd-ssd"
874+
type = "%s"
850875
zone = "us-central1-a"
851876
labels = {
852877
my-label = "my-updated-label-value"
853878
a-new-label = "a-new-label-value"
854879
}
855880
}
856-
`, diskName)
881+
`, diskName, diskType)
857882
}
858883

859884
func testAccComputeDisk_fromSnapshot(projectName, firstDiskName, snapshotName, diskName, ref_selector string) string {

google/services/compute/resource_compute_instance.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,10 @@ func ResourceComputeInstance() *schema.Resource {
292292
},
293293

294294
"machine_type": {
295-
Type: schema.TypeString,
296-
Required: true,
297-
Description: `The machine type to create.`,
295+
Type: schema.TypeString,
296+
Required: true,
297+
Description: `The machine type to create.`,
298+
DiffSuppressFunc: tpgresource.CompareResourceNames,
298299
},
299300

300301
"name": {

google/services/compute/resource_compute_instance_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,30 @@ func TestAccComputeInstance_resourceManagerTags(t *testing.T) {
273273
})
274274
}
275275

276+
func TestAccComputeInstance_machineTypeUrl(t *testing.T) {
277+
t.Parallel()
278+
279+
var instance compute.Instance
280+
var instanceName = fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
281+
var machineTypeUrl = "zones/us-central1-a/machineTypes/e2-medium"
282+
283+
acctest.VcrTest(t, resource.TestCase{
284+
PreCheck: func() { acctest.AccTestPreCheck(t) },
285+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
286+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
287+
Steps: []resource.TestStep{
288+
{
289+
Config: testAccComputeInstance_machineType(instanceName, machineTypeUrl),
290+
Check: resource.ComposeTestCheckFunc(
291+
testAccCheckComputeInstanceExists(
292+
t, "google_compute_instance.foobar", &instance),
293+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "description", "old_desc"),
294+
),
295+
},
296+
},
297+
})
298+
}
299+
276300
func TestAccComputeInstance_descriptionUpdate(t *testing.T) {
277301
t.Parallel()
278302

@@ -3692,6 +3716,32 @@ resource "google_compute_instance" "foobar" {
36923716
`, instance)
36933717
}
36943718

3719+
func testAccComputeInstance_machineType(instance string, machineType string) string {
3720+
return fmt.Sprintf(`
3721+
data "google_compute_image" "my_image" {
3722+
family = "debian-11"
3723+
project = "debian-cloud"
3724+
}
3725+
3726+
resource "google_compute_instance" "foobar" {
3727+
name = "%s"
3728+
machine_type = "%s"
3729+
zone = "us-central1-a"
3730+
description = "old_desc"
3731+
3732+
boot_disk {
3733+
initialize_params {
3734+
image = data.google_compute_image.my_image.self_link
3735+
}
3736+
}
3737+
3738+
network_interface {
3739+
network = "default"
3740+
}
3741+
}
3742+
`, instance, machineType)
3743+
}
3744+
36953745
func testAccComputeInstance_description(instance string) string {
36963746
return fmt.Sprintf(`
36973747
data "google_compute_image" "my_image" {

0 commit comments

Comments
 (0)