From a0243ac7f7968c2593195a9c4dad07bbfaf97404 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 10 Sep 2021 15:09:04 -0500 Subject: [PATCH] Remove disk interface, tests (#5185) (#3611) * Remove disk interface tests * Remove region disk test also * Fix api compile * Add DSF to always suppress diff, readd default * Remove unused method from GA Signed-off-by: Modular Magician --- .changelog/5185.txt | 3 ++ google-beta/common_diff_suppress.go | 5 +++ google-beta/resource_compute_disk.go | 35 ++++------------- .../resource_compute_disk_generated_test.go | 2 +- google-beta/resource_compute_disk_test.go | 39 ------------------- google-beta/resource_compute_region_disk.go | 35 ++++------------- ...urce_compute_region_disk_generated_test.go | 2 +- .../resource_compute_region_disk_test.go | 33 ---------------- ...esource_gke_hub_feature_membership_test.go | 2 +- website/docs/r/compute_disk.html.markdown | 2 - .../docs/r/compute_region_disk.html.markdown | 2 - 11 files changed, 25 insertions(+), 135 deletions(-) create mode 100644 .changelog/5185.txt diff --git a/.changelog/5185.txt b/.changelog/5185.txt new file mode 100644 index 0000000000..037adf87c2 --- /dev/null +++ b/.changelog/5185.txt @@ -0,0 +1,3 @@ +```release-note:deprecation +compute: deprecated `interface` field on `google_compute_disk` and `google_compute_region_disk` (beta only) +``` diff --git a/google-beta/common_diff_suppress.go b/google-beta/common_diff_suppress.go index 03b497a632..67bbba9323 100644 --- a/google-beta/common_diff_suppress.go +++ b/google-beta/common_diff_suppress.go @@ -195,3 +195,8 @@ func compareIpAddressOrSelfLinkOrResourceName(_, old, new string, _ *schema.Reso // otherwise compare as self links return compareSelfLinkOrResourceName("", old, new, nil) } + +// Suppress all diffs, used for Disk.Interface which is a nonfunctional field +func alwaysDiffSuppress(_, _, _ string, _ *schema.ResourceData) bool { + return true +} diff --git a/google-beta/resource_compute_disk.go b/google-beta/resource_compute_disk.go index c3e340fd68..fbed6f77f9 100644 --- a/google-beta/resource_compute_disk.go +++ b/google-beta/resource_compute_disk.go @@ -25,7 +25,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "google.golang.org/api/googleapi" ) @@ -347,12 +346,13 @@ For instance, the image 'centos-6-v20180104' includes its family name 'centos-6' These images can be referred by family name here.`, }, "interface": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{"SCSI", "NVME", ""}, false), - Description: `Specifies the disk interface to use for attaching this disk, which is either SCSI or NVME. The default is SCSI. Default value: "SCSI" Possible values: ["SCSI", "NVME"]`, - Default: "SCSI", + Type: schema.TypeString, + Optional: true, + Deprecated: "This field is no longer in use, disk interfaces will be automatically determined on attachment. To resolve this issue, remove this field from your config.", + ForceNew: true, + DiffSuppressFunc: alwaysDiffSuppress, + Description: `Specifies the disk interface to use for attaching this disk, which is either SCSI or NVME. The default is SCSI.`, + Default: "SCSI", }, "labels": { Type: schema.TypeMap, @@ -646,12 +646,6 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error { } else if v, ok := d.GetOkExists("physical_block_size_bytes"); !isEmptyValue(reflect.ValueOf(physicalBlockSizeBytesProp)) && (ok || !reflect.DeepEqual(v, physicalBlockSizeBytesProp)) { obj["physicalBlockSizeBytes"] = physicalBlockSizeBytesProp } - interfaceProp, err := expandComputeDiskInterface(d.Get("interface"), d, config) - if err != nil { - return err - } else if v, ok := d.GetOkExists("interface"); !isEmptyValue(reflect.ValueOf(interfaceProp)) && (ok || !reflect.DeepEqual(v, interfaceProp)) { - obj["interface"] = interfaceProp - } typeProp, err := expandComputeDiskType(d.Get("type"), d, config) if err != nil { return err @@ -840,9 +834,6 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("physical_block_size_bytes", flattenComputeDiskPhysicalBlockSizeBytes(res["physicalBlockSizeBytes"], d, config)); err != nil { return fmt.Errorf("Error reading Disk: %s", err) } - if err := d.Set("interface", flattenComputeDiskInterface(res["interface"], d, config)); err != nil { - return fmt.Errorf("Error reading Disk: %s", err) - } if err := d.Set("type", flattenComputeDiskType(res["type"], d, config)); err != nil { return fmt.Errorf("Error reading Disk: %s", err) } @@ -1172,14 +1163,6 @@ func flattenComputeDiskPhysicalBlockSizeBytes(v interface{}, d *schema.ResourceD return v // let terraform core handle it otherwise } -func flattenComputeDiskInterface(v interface{}, d *schema.ResourceData, config *Config) interface{} { - if v == nil || isEmptyValue(reflect.ValueOf(v)) { - return "SCSI" - } - - return v -} - func flattenComputeDiskType(v interface{}, d *schema.ResourceData, config *Config) interface{} { if v == nil { return v @@ -1377,10 +1360,6 @@ func expandComputeDiskPhysicalBlockSizeBytes(v interface{}, d TerraformResourceD return v, nil } -func expandComputeDiskInterface(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - return v, nil -} - func expandComputeDiskType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { f, err := parseZonalFieldValue("diskTypes", v.(string), "project", "zone", d, config, true) if err != nil { diff --git a/google-beta/resource_compute_disk_generated_test.go b/google-beta/resource_compute_disk_generated_test.go index 7e28d7509a..19e3032a44 100644 --- a/google-beta/resource_compute_disk_generated_test.go +++ b/google-beta/resource_compute_disk_generated_test.go @@ -42,7 +42,7 @@ func TestAccComputeDisk_diskBasicExample(t *testing.T) { ResourceName: "google_compute_disk.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"type", "zone", "snapshot"}, + ImportStateVerifyIgnore: []string{"interface", "type", "zone", "snapshot"}, }, }, }) diff --git a/google-beta/resource_compute_disk_test.go b/google-beta/resource_compute_disk_test.go index fc818ff3d9..f1454f8354 100644 --- a/google-beta/resource_compute_disk_test.go +++ b/google-beta/resource_compute_disk_test.go @@ -458,27 +458,6 @@ func TestAccComputeDisk_resourcePolicies(t *testing.T) { }) } -func TestAccComputeDisk_interface(t *testing.T) { - t.Parallel() - - diskName := fmt.Sprintf("tf-test-%s", randString(t, 10)) - - vcrTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccComputeDisk_interface(diskName), - }, - { - ResourceName: "google_compute_disk.foobar", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - func TestAccComputeDisk_multiWriter(t *testing.T) { t.Parallel() instanceName := fmt.Sprintf("tf-test-%s", randString(t, 10)) @@ -817,24 +796,6 @@ resource "google_compute_disk" "foobar" { `, policyName, diskName) } -func testAccComputeDisk_interface(diskName string) string { - return fmt.Sprintf(` -data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" -} - -resource "google_compute_disk" "foobar" { - name = "%s" - image = data.google_compute_image.my_image.self_link - size = 50 - type = "pd-ssd" - zone = "us-central1-a" - interface = "NVME" -} -`, diskName) -} - func testAccComputeDisk_multiWriter(instance string, diskName string, enableMultiwriter bool) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { diff --git a/google-beta/resource_compute_region_disk.go b/google-beta/resource_compute_region_disk.go index fc3064e798..a70565efcc 100644 --- a/google-beta/resource_compute_region_disk.go +++ b/google-beta/resource_compute_region_disk.go @@ -24,7 +24,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "google.golang.org/api/googleapi" ) @@ -123,12 +122,13 @@ encryption key that protects this resource.`, }, }, "interface": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{"SCSI", "NVME", ""}, false), - Description: `Specifies the disk interface to use for attaching this disk, which is either SCSI or NVME. The default is SCSI. Default value: "SCSI" Possible values: ["SCSI", "NVME"]`, - Default: "SCSI", + Type: schema.TypeString, + Optional: true, + Deprecated: "This field is no longer in use, disk interfaces will be automatically determined on attachment. To resolve this issue, remove this field from your config.", + ForceNew: true, + DiffSuppressFunc: alwaysDiffSuppress, + Description: `Specifies the disk interface to use for attaching this disk, which is either SCSI or NVME. The default is SCSI.`, + Default: "SCSI", }, "labels": { Type: schema.TypeMap, @@ -335,12 +335,6 @@ func resourceComputeRegionDiskCreate(d *schema.ResourceData, meta interface{}) e } else if v, ok := d.GetOkExists("type"); !isEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) { obj["type"] = typeProp } - interfaceProp, err := expandComputeRegionDiskInterface(d.Get("interface"), d, config) - if err != nil { - return err - } else if v, ok := d.GetOkExists("interface"); !isEmptyValue(reflect.ValueOf(interfaceProp)) && (ok || !reflect.DeepEqual(v, interfaceProp)) { - obj["interface"] = interfaceProp - } regionProp, err := expandComputeRegionDiskRegion(d.Get("region"), d, config) if err != nil { return err @@ -499,9 +493,6 @@ func resourceComputeRegionDiskRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("type", flattenComputeRegionDiskType(res["type"], d, config)); err != nil { return fmt.Errorf("Error reading RegionDisk: %s", err) } - if err := d.Set("interface", flattenComputeRegionDiskInterface(res["interface"], d, config)); err != nil { - return fmt.Errorf("Error reading RegionDisk: %s", err) - } if err := d.Set("region", flattenComputeRegionDiskRegion(res["region"], d, config)); err != nil { return fmt.Errorf("Error reading RegionDisk: %s", err) } @@ -824,14 +815,6 @@ func flattenComputeRegionDiskType(v interface{}, d *schema.ResourceData, config return NameFromSelfLinkStateFunc(v) } -func flattenComputeRegionDiskInterface(v interface{}, d *schema.ResourceData, config *Config) interface{} { - if v == nil || isEmptyValue(reflect.ValueOf(v)) { - return "SCSI" - } - - return v -} - func flattenComputeRegionDiskRegion(v interface{}, d *schema.ResourceData, config *Config) interface{} { if v == nil { return v @@ -963,10 +946,6 @@ func expandComputeRegionDiskType(v interface{}, d TerraformResourceData, config return f.RelativeLink(), nil } -func expandComputeRegionDiskInterface(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - return v, nil -} - func expandComputeRegionDiskRegion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true) if err != nil { diff --git a/google-beta/resource_compute_region_disk_generated_test.go b/google-beta/resource_compute_region_disk_generated_test.go index a1e5e4a25b..a2cb353689 100644 --- a/google-beta/resource_compute_region_disk_generated_test.go +++ b/google-beta/resource_compute_region_disk_generated_test.go @@ -42,7 +42,7 @@ func TestAccComputeRegionDisk_regionDiskBasicExample(t *testing.T) { ResourceName: "google_compute_region_disk.regiondisk", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"type", "region", "snapshot"}, + ImportStateVerifyIgnore: []string{"type", "interface", "region", "snapshot"}, }, }, }) diff --git a/google-beta/resource_compute_region_disk_test.go b/google-beta/resource_compute_region_disk_test.go index 018cdd8af7..9865927c1b 100644 --- a/google-beta/resource_compute_region_disk_test.go +++ b/google-beta/resource_compute_region_disk_test.go @@ -174,39 +174,6 @@ func TestAccComputeRegionDisk_deleteDetach(t *testing.T) { }) } -func TestAccComputeRegionDisk_interface(t *testing.T) { - t.Parallel() - - diskName := fmt.Sprintf("tf-test-%s", randString(t, 10)) - - vcrTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccComputeRegionDisk_interface(diskName), - }, - { - ResourceName: "google_compute_region_disk.foobar", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccComputeRegionDisk_interface(diskName string) string { - return fmt.Sprintf(` -resource "google_compute_region_disk" "foobar" { - name = "%s" - size = 50 - type = "pd-ssd" - interface = "NVME" - replica_zones = ["us-central1-a", "us-central1-f"] -} -`, diskName) -} - func testAccCheckComputeRegionDiskExists(t *testing.T, n string, disk *computeBeta.Disk) resource.TestCheckFunc { return func(s *terraform.State) error { p := getTestProjectFromEnv() diff --git a/google-beta/resource_gke_hub_feature_membership_test.go b/google-beta/resource_gke_hub_feature_membership_test.go index 32fa84c196..9e1f2ea64d 100644 --- a/google-beta/resource_gke_hub_feature_membership_test.go +++ b/google-beta/resource_gke_hub_feature_membership_test.go @@ -5,7 +5,7 @@ import ( "fmt" "testing" - dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl" + "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl" gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" diff --git a/website/docs/r/compute_disk.html.markdown b/website/docs/r/compute_disk.html.markdown index 3dc8a97f92..519299fb6e 100644 --- a/website/docs/r/compute_disk.html.markdown +++ b/website/docs/r/compute_disk.html.markdown @@ -123,8 +123,6 @@ The following arguments are supported: * `interface` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) Specifies the disk interface to use for attaching this disk, which is either SCSI or NVME. The default is SCSI. - Default value is `SCSI`. - Possible values are `SCSI` and `NVME`. * `type` - (Optional) diff --git a/website/docs/r/compute_region_disk.html.markdown b/website/docs/r/compute_region_disk.html.markdown index 284f176611..ec56420074 100644 --- a/website/docs/r/compute_region_disk.html.markdown +++ b/website/docs/r/compute_region_disk.html.markdown @@ -141,8 +141,6 @@ The following arguments are supported: * `interface` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) Specifies the disk interface to use for attaching this disk, which is either SCSI or NVME. The default is SCSI. - Default value is `SCSI`. - Possible values are `SCSI` and `NVME`. * `region` - (Optional)