Skip to content

Commit

Permalink
Add interface to regional disks (#4727) (#3193)
Browse files Browse the repository at this point in the history
Co-authored-by: upodroid <cy@borg.dev>
Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: upodroid <cy@borg.dev>
  • Loading branch information
modular-magician and upodroid authored Apr 23, 2021
1 parent 4968f45 commit e1ee289
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/4727.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `interface` field to `google_compute_region_disk` (beta)
```
26 changes: 26 additions & 0 deletions google-beta/resource_compute_region_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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 @@ -121,6 +122,14 @@ 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",
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -326,6 +335,12 @@ 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 @@ -484,6 +499,9 @@ 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 @@ -806,6 +824,10 @@ func flattenComputeRegionDiskType(v interface{}, d *schema.ResourceData, config
return NameFromSelfLinkStateFunc(v)
}

func flattenComputeRegionDiskInterface(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenComputeRegionDiskRegion(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -937,6 +959,10 @@ 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
37 changes: 33 additions & 4 deletions google-beta/resource_compute_region_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,39 @@ 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 Expand Up @@ -295,8 +328,6 @@ resource "google_compute_region_disk" "regiondisk" {
name = "%s"
snapshot = google_compute_snapshot.snapdisk.%s
type = "pd-ssd"
region = "us-central1"
replica_zones = ["us-central1-a", "us-central1-f"]
}
`, diskName, diskName, diskName, refSelector)
Expand Down Expand Up @@ -356,7 +387,6 @@ resource "google_compute_region_disk" "regiondisk" {
name = "%s"
snapshot = google_compute_snapshot.snapdisk.self_link
type = "pd-ssd"
region = "us-central1"
replica_zones = ["us-central1-a", "us-central1-f"]
Expand Down Expand Up @@ -387,7 +417,6 @@ resource "google_compute_region_disk" "regiondisk" {
name = "%s"
snapshot = google_compute_snapshot.snapdisk.self_link
type = "pd-ssd"
region = "us-central1"
replica_zones = ["us-central1-a", "us-central1-f"]
}
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_dataflow_flex_template_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
compute "google.golang.org/api/compute/v1"
"google.golang.org/api/compute/v1"
)

func TestAccDataflowFlexTemplateJob_basic(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions google-beta/resource_dataproc_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"google.golang.org/api/googleapi"

dataproc "google.golang.org/api/dataproc/v1beta2"
"google.golang.org/api/googleapi"
)

func TestDataprocExtractInitTimeout(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/compute_region_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ The following arguments are supported:
URL of the disk type resource describing which disk type to use to
create the disk. Provide this when creating the disk.

* `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)
A reference to the region where the disk resides.
Expand Down

0 comments on commit e1ee289

Please sign in to comment.