Skip to content

Commit

Permalink
Add support of provisioned iops and throughput on boot disk. (#9649) (#…
Browse files Browse the repository at this point in the history
…16871)

[upstream:b3eada0996063fbb3a6ade12770ea64eef87f5cc]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Dec 27, 2023
1 parent 88d096a commit 27f6e11
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/9649.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `provisioned_iops`and `provisioned_throughput` fields under `boot_disk.initialize_params` to `google_compute_instance` resource
```
40 changes: 36 additions & 4 deletions google/services/compute/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var (
"boot_disk.0.initialize_params.0.image",
"boot_disk.0.initialize_params.0.labels",
"boot_disk.0.initialize_params.0.resource_manager_tags",
"boot_disk.0.initialize_params.0.provisioned_iops",
"boot_disk.0.initialize_params.0.provisioned_throughput",
}

schedulingKeys = []string{
Expand Down Expand Up @@ -234,6 +236,26 @@ func ResourceComputeInstance() *schema.Resource {
ForceNew: true,
Description: `A map of resource manager tags. Resource manager tag keys and values have the same definition as resource manager tags. Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456. The field is ignored (both PUT & PATCH) when empty.`,
},

"provisioned_iops": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
Computed: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(10000, 120000),
Description: `Indicates how many IOPS to provision for the disk. This sets the number of I/O operations per second that the disk can handle. Values must be between 10,000 and 120,000.`,
},

"provisioned_throughput": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
Computed: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(1, 7124),
Description: `Indicates how much throughput to provision for the disk. This sets the number of throughput mb per second that the disk can handle. Values must be between 1 and 7,124.`,
},
},
},
},
Expand Down Expand Up @@ -2596,6 +2618,14 @@ func expandBootDisk(d *schema.ResourceData, config *transport_tpg.Config, projec
disk.InitializeParams.DiskSizeGb = int64(v.(int))
}

if v, ok := d.GetOk("boot_disk.0.initialize_params.0.provisioned_iops"); ok {
disk.InitializeParams.ProvisionedIops = int64(v.(int))
}

if v, ok := d.GetOk("boot_disk.0.initialize_params.0.provisioned_throughput"); ok {
disk.InitializeParams.ProvisionedThroughput = int64(v.(int))
}

if v, ok := d.GetOk("boot_disk.0.initialize_params.0.type"); ok {
diskTypeName := v.(string)
diskType, err := readDiskType(config, d, diskTypeName)
Expand Down Expand Up @@ -2657,10 +2687,12 @@ func flattenBootDisk(d *schema.ResourceData, disk *compute.AttachedDisk, config
"type": tpgresource.GetResourceNameFromSelfLink(diskDetails.Type),
// If the config specifies a family name that doesn't match the image name, then
// the diff won't be properly suppressed. See DiffSuppressFunc for this field.
"image": diskDetails.SourceImage,
"size": diskDetails.SizeGb,
"labels": diskDetails.Labels,
"resource_manager_tags": d.Get("boot_disk.0.initialize_params.0.resource_manager_tags"),
"image": diskDetails.SourceImage,
"size": diskDetails.SizeGb,
"labels": diskDetails.Labels,
"resource_manager_tags": d.Get("boot_disk.0.initialize_params.0.resource_manager_tags"),
"provisioned_iops": diskDetails.ProvisionedIops,
"provisioned_throughput": diskDetails.ProvisionedThroughput,
}}
}

Expand Down
54 changes: 54 additions & 0 deletions google/services/compute/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,29 @@ func TestAccComputeInstanceConfidentialInstanceConfigMain(t *testing.T) {
})
}

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

context := map[string]interface{}{
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
"zone": "us-central1-a",
"provisioned_iops": 12000,
"provisioned_throughput": 200,
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceHyperDiskBootDiskProvisionedIopsThroughput(context),
},
computeInstanceImportStep(context["zone"].(string), context["instance_name"].(string), []string{"allow_stopping_for_update"}),
},
})
}

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

Expand Down Expand Up @@ -6307,6 +6330,37 @@ resource "google_compute_instance" "foobar" {
`, instance, enableConfidentialCompute)
}

func testAccComputeInstanceHyperDiskBootDiskProvisionedIopsThroughput(context map[string]interface{}) string {
return acctest.Nprintf(`
data "google_compute_image" "my_image" {
family = "ubuntu-2204-lts"
project = "ubuntu-os-cloud"
}
data "google_project" "project" {}
resource "google_compute_instance" "foobar" {
name = "%{instance_name}"
machine_type = "h3-standard-88"
zone = "%{zone}"
boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
provisioned_iops = %{provisioned_iops}
provisioned_throughput = %{provisioned_throughput}
type = "hyperdisk-balanced"
size = 100
}
}
network_interface {
network = "default"
}
}
`, context)
}

func testAccComputeInstance_enableDisplay(instance string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down
16 changes: 16 additions & 0 deletions website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,22 @@ is desired, you will need to modify your state file manually using

* `resource_manager_tags` - (Optional) A tag is a key-value pair that can be attached to a Google Cloud resource. You can use tags to conditionally allow or deny policies based on whether a resource has a specific tag. This value is not returned by the API. In Terraform, this value cannot be updated and changing it will recreate the resource.

* `provisioned_iops` - (Optional) Indicates how many IOPS to provision for the disk.
This sets the number of I/O operations per second that the disk can handle.
Values must be between 10,000 and 120,000. For more details,see the
[Extreme persistent disk documentation](https://cloud.google.com/compute/docs/disks/extreme-persistent-disk).
Note: Updating currently is only supported for hyperdisk skus via disk update
api/gcloud 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.

* `provisioned_throughput` - (Optional) Indicates how much throughput to provision for the disk.
This sets the number of throughput mb per second that the disk can handle.
Values must be between 1 and 7,124. Note: Updating currently is only supported
for hyperdisk skus via disk update api/gcloud 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.

<a name="nested_scratch_disk"></a>The `scratch_disk` block supports:

* `interface` - (Required) The disk interface to use for attaching this disk; either SCSI or NVME.
Expand Down

0 comments on commit 27f6e11

Please sign in to comment.