Skip to content

Commit

Permalink
Add Provisioned IOPS support (#4578) (#3269)
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 May 19, 2021
1 parent 59fa203 commit df5c80c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/4578.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `provisioned_iops` to `google_compute_disk`
```
36 changes: 36 additions & 0 deletions google-beta/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ are 4096 and 16384, other sizes may be added in the future.
If an unsupported value is requested, the error message will list
the supported values for the caller's project.`,
},
"provisioned_iops": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `Indicates how many IOPS must be provisioned for the disk.`,
},
"resource_policies": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -670,6 +676,12 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
} else if v, ok := d.GetOkExists("multi_writer"); !isEmptyValue(reflect.ValueOf(multiWriterProp)) && (ok || !reflect.DeepEqual(v, multiWriterProp)) {
obj["multiWriter"] = multiWriterProp
}
provisionedIopsProp, err := expandComputeDiskProvisionedIops(d.Get("provisioned_iops"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("provisioned_iops"); !isEmptyValue(reflect.ValueOf(provisionedIopsProp)) && (ok || !reflect.DeepEqual(v, provisionedIopsProp)) {
obj["provisionedIops"] = provisionedIopsProp
}
zoneProp, err := expandComputeDiskZone(d.Get("zone"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -843,6 +855,9 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("multi_writer", flattenComputeDiskMultiWriter(res["multiWriter"], d, config)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
if err := d.Set("provisioned_iops", flattenComputeDiskProvisionedIops(res["provisionedIops"], d, config)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
if err := d.Set("zone", flattenComputeDiskZone(res["zone"], d, config)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
Expand Down Expand Up @@ -1183,6 +1198,23 @@ func flattenComputeDiskMultiWriter(v interface{}, d *schema.ResourceData, config
return v
}

func flattenComputeDiskProvisionedIops(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenComputeDiskZone(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1377,6 +1409,10 @@ func expandComputeDiskMultiWriter(v interface{}, d TerraformResourceData, config
return v, nil
}

func expandComputeDiskProvisionedIops(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeDiskZone(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("zones", v.(string), "project", d, config, true)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ data "google_compute_image" "my_image" {
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"
size = 1000
type = "pd-extreme"
zone = "us-central1-c"
labels = {
my-label = "my-label-value"
}
provisioned_iops = 90000
}
resource "google_compute_resource_policy" "foobar" {
Expand All @@ -74,7 +75,7 @@ resource "google_compute_resource_policy" "foobar" {
resource "google_compute_disk_resource_policy_attachment" "foobar" {
name = google_compute_resource_policy.foobar.name
disk = google_compute_disk.foobar.name
zone = "us-central1-a"
zone = "us-central1-c"
}
`, diskName, policyName)
}
4 changes: 4 additions & 0 deletions website/docs/r/compute_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ The following arguments are supported:
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Indicates whether or not the disk can be read/write attached to more than one instance.

* `provisioned_iops` -
(Optional)
Indicates how many IOPS must be provisioned for the disk.

* `zone` -
(Optional)
A reference to the zone where the disk resides.
Expand Down

0 comments on commit df5c80c

Please sign in to comment.