Skip to content

Commit

Permalink
Adding in additional field for provisioned_throughput for Hyper disk …
Browse files Browse the repository at this point in the history
…Throughput SKUs (GoogleCloudPlatform#8153)
  • Loading branch information
NA2047 authored and ericayyliu committed Jul 26, 2023
1 parent 892edd3 commit 57e4d9c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
12 changes: 11 additions & 1 deletion mmv1/products/compute/Disk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,21 @@ properties:
name: 'provisionedIops'
description: |
Indicates how many IOPS must be provisioned for the disk.
Note: Update currently only supported by hyperdisk skus, allowing for an update of IOPS every 4 hours
Note: Updating currently is only supported by hyperdisk skus without the need to delete and recreate the disk, hyperdisk
allows for an update of IOPS every 4 hours. To update your hyperdisk more frequently, you'll need to manually delete and recreate it
required: false
default_from_api: true
update_verb: :PATCH
update_url: 'projects/{{project}}/zones/{{zone}}/disks/{{name}}?paths=provisionedIops'
- !ruby/object:Api::Type::Integer
name: 'provisionedThroughput'
description: |
Indicates how much Throughput must be provisioned for the disk.
Note: Updating currently is only supported by hyperdisk skus without the need to delete and recreate the disk, hyperdisk
allows for an update of Throughput every 4 hours. To update your hyperdisk more frequently, you'll need to manually delete and recreate it
default_from_api: true
update_verb: :PATCH
update_url: 'projects/{{project}}/zones/{{zone}}/disks/{{name}}?paths=provisionedThroughput'
- !ruby/object:Api::Type::NestedObject
name: 'asyncPrimaryDisk'
min_version: 'beta'
Expand Down
2 changes: 1 addition & 1 deletion mmv1/templates/terraform/update_encoder/hyper_disk.go.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

if d.HasChange("provisioned_iops") && strings.Contains(d.Get("type").(string), "hyperdisk"){
if (d.HasChange("provisioned_iops") && strings.Contains(d.Get("type").(string), "hyperdisk")) || (d.HasChange("provisioned_throughput") && strings.Contains(d.Get("type").(string), "hyperdisk")) {
nameProp := d.Get("name")
if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
Expand Down
80 changes: 72 additions & 8 deletions mmv1/third_party/terraform/tests/resource_compute_disk_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,16 @@ func TestAccComputeDisk_pdHyperDiskProvisionedIopsLifeCycle(t *testing.T) {
context_1 := map[string]interface{}{
"random_suffix": RandString(t, 10),
"provisioned_iops": 10000,
"disk_size": 64,
"lifecycle_bool": true,
}
context_2 := map[string]interface{}{
"random_suffix": context_1["random_suffix"],
"provisioned_iops": 11000,
"disk_size": 64,
"lifecycle_bool": true,
}
context_3 := map[string]interface{}{
"random_suffix": context_1["random_suffix"],
"provisioned_iops": 11000,
"disk_size": 64,
"lifecycle_bool": false,
}

Expand Down Expand Up @@ -409,6 +406,58 @@ func TestAccComputeDisk_pdHyperDiskProvisionedIopsLifeCycle(t *testing.T) {
})
}

func TestAccComputeDisk_pdHyperDiskProvisionedThroughputLifeCycle(t *testing.T) {
t.Parallel()

context_1 := map[string]interface{}{
"random_suffix": RandString(t, 10),
"provisioned_throughput": 180,
"lifecycle_bool": true,
}
context_2 := map[string]interface{}{
"random_suffix": context_1["random_suffix"],
"provisioned_throughput": 20,
"lifecycle_bool": true,
}
context_3 := map[string]interface{}{
"random_suffix": context_1["random_suffix"],
"provisioned_throughput": 20,
"lifecycle_bool": false,
}

VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeDiskDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeDisk_pdHyperDiskProvisionedThroughputLifeCycle(context_1),
},
{
ResourceName: "google_compute_disk.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeDisk_pdHyperDiskProvisionedThroughputLifeCycle(context_2),
},
{
ResourceName: "google_compute_disk.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeDisk_pdHyperDiskProvisionedThroughputLifeCycle(context_3),
},
{
ResourceName: "google_compute_disk.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccComputeDisk_fromSnapshot(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -977,12 +1026,27 @@ resource "google_compute_instance_group_manager" "manager" {
func testAccComputeDisk_pdHyperDiskProvisionedIopsLifeCycle(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_disk" "foobar" {
name = "tf-test-hyperdisk-%{random_suffix}"
type = "hyperdisk-extreme"
provisioned_iops = %{provisioned_iops}
size = %{disk_size}
name = "tf-test-hyperdisk-%{random_suffix}"
type = "hyperdisk-extreme"
provisioned_iops = %{provisioned_iops}
size = 64
lifecycle {
prevent_destroy = %{lifecycle_bool}
}
}
`, context)
}

func testAccComputeDisk_pdHyperDiskProvisionedThroughputLifeCycle(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_disk" "foobar" {
name = "tf-test-hyperdisk-%{random_suffix}"
type = "hyperdisk-throughput"
zone = "us-east4-c"
provisioned_throughput = %{provisioned_throughput}
size = 2048
lifecycle {
prevent_destroy = %{lifecycle_bool}
prevent_destroy = %{lifecycle_bool}
}
}
`, context)
Expand Down

0 comments on commit 57e4d9c

Please sign in to comment.