Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Provisioned IOPS support #9193

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,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.`,
},
"size": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -620,6 +626,12 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
} else if v, ok := d.GetOkExists("image"); !isEmptyValue(reflect.ValueOf(sourceImageProp)) && (ok || !reflect.DeepEqual(v, sourceImageProp)) {
obj["sourceImage"] = sourceImageProp
}
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 @@ -784,6 +796,9 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("image", flattenComputeDiskImage(res["sourceImage"], 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 @@ -1109,6 +1124,23 @@ func flattenComputeDiskImage(v interface{}, d *schema.ResourceData, config *Conf
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 @@ -1279,6 +1311,10 @@ func expandComputeDiskImage(v interface{}, d TerraformResourceData, config *Conf
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