Skip to content

Commit

Permalink
Remove disk interface, tests (#5185) (#3611)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
modular-magician authored and slevenick committed Sep 10, 2021
1 parent 0401afb commit 1cbd681
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 134 deletions.
3 changes: 3 additions & 0 deletions .changelog/5185.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:deprecation
compute: deprecated `interface` field on `google_compute_disk` and `google_compute_region_disk` (beta only)
```
5 changes: 5 additions & 0 deletions google-beta/common_diff_suppress.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,8 @@ func durationDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
}
return oDuration == nDuration
}

// Suppress all diffs, used for Disk.Interface which is a nonfunctional field
func alwaysDiffSuppress(_, _, _ string, _ *schema.ResourceData) bool {
return true
}
35 changes: 7 additions & 28 deletions google-beta/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_compute_disk_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
})
Expand Down
39 changes: 0 additions & 39 deletions google-beta/resource_compute_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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" {
Expand Down
35 changes: 7 additions & 28 deletions google-beta/resource_compute_region_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_compute_region_disk_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
})
Expand Down
33 changes: 0 additions & 33 deletions google-beta/resource_compute_region_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/compute_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/compute_region_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1cbd681

Please sign in to comment.