Skip to content

Commit 4b7d5c5

Browse files
authored
Revert "Allow updating guest accelerator count to 0 on compute_instance" (#15594)
1 parent 193f796 commit 4b7d5c5

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,23 +3376,12 @@ func suppressEmptyGuestAcceleratorDiff(_ context.Context, d *schema.ResourceDiff
33763376
return nil
33773377
}
33783378

3379-
// Check if old had a non-zero count
3380-
if len(old) > 0 {
3381-
if apiAccel, ok := old[0].(map[string]interface{}); ok {
3382-
if oldCount, ok := apiAccel["count"].(int); ok && oldCount != 0 {
3383-
// Old count wasn't 0, so don't clear the diff
3384-
return nil
3385-
}
3386-
}
3387-
}
3388-
3389-
// Check new accelerator configuration
3390-
configAccel, ok := new[0].(map[string]interface{})
3379+
firstAccel, ok := new[0].(map[string]interface{})
33913380
if !ok {
33923381
return fmt.Errorf("Unable to type assert guest accelerator")
33933382
}
33943383

3395-
if configAccel["count"].(int) == 0 {
3384+
if firstAccel["count"].(int) == 0 {
33963385
if err := d.Clear("guest_accelerator"); err != nil {
33973386
return err
33983387
}

mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,16 +2504,10 @@ func TestAccComputeInstance_guestAccelerator(t *testing.T) {
25042504
testAccCheckComputeInstanceHasGuestAccelerator(&instance, "nvidia-tesla-t4", 1),
25052505
),
25062506
},
2507-
{
2508-
Config: testAccComputeInstance_guestAccelerator(instanceName, 0),
2509-
Check: resource.ComposeTestCheckFunc(
2510-
testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
2511-
testAccCheckComputeInstanceHasGuestAccelerator(&instance, "nvidia-tesla-t4", 0),
2512-
),
2513-
},
25142507
computeInstanceImportStep("us-east1-d", instanceName, []string{"metadata.baz", "metadata.foo"}),
25152508
},
25162509
})
2510+
25172511
}
25182512

25192513
func TestAccComputeInstance_guestAcceleratorSkip(t *testing.T) {
@@ -5847,9 +5841,6 @@ func testAccCheckComputeInstanceHasMultiNic(instance *compute.Instance) resource
58475841
func testAccCheckComputeInstanceHasGuestAccelerator(instance *compute.Instance, acceleratorType string, acceleratorCount int64) resource.TestCheckFunc {
58485842
return func(s *terraform.State) error {
58495843
if len(instance.GuestAccelerators) != 1 {
5850-
if int(acceleratorCount) == 0 && len(instance.GuestAccelerators) == 0 {
5851-
return nil
5852-
}
58535844
return fmt.Errorf("Expected only one guest accelerator")
58545845
}
58555846

0 commit comments

Comments
 (0)