Skip to content

Commit dbd5648

Browse files
Add support of provisioned iops and throughput on boot disk. (#9649) (#6792)
[upstream:b3eada0996063fbb3a6ade12770ea64eef87f5cc] Signed-off-by: Modular Magician <[email protected]>
1 parent 07034c2 commit dbd5648

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

.changelog/9649.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `provisioned_iops`and `provisioned_throughput` fields under `boot_disk.initialize_params` to `google_compute_instance` resource
3+
```

google-beta/services/compute/resource_compute_instance.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ var (
4343
"boot_disk.0.initialize_params.0.image",
4444
"boot_disk.0.initialize_params.0.labels",
4545
"boot_disk.0.initialize_params.0.resource_manager_tags",
46+
"boot_disk.0.initialize_params.0.provisioned_iops",
47+
"boot_disk.0.initialize_params.0.provisioned_throughput",
4648
"boot_disk.0.initialize_params.0.enable_confidential_compute",
4749
}
4850

@@ -237,6 +239,27 @@ func ResourceComputeInstance() *schema.Resource {
237239
ForceNew: true,
238240
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.`,
239241
},
242+
243+
"provisioned_iops": {
244+
Type: schema.TypeInt,
245+
Optional: true,
246+
AtLeastOneOf: initializeParamsKeys,
247+
Computed: true,
248+
ForceNew: true,
249+
ValidateFunc: validation.IntBetween(10000, 120000),
250+
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.`,
251+
},
252+
253+
"provisioned_throughput": {
254+
Type: schema.TypeInt,
255+
Optional: true,
256+
AtLeastOneOf: initializeParamsKeys,
257+
Computed: true,
258+
ForceNew: true,
259+
ValidateFunc: validation.IntBetween(1, 7124),
260+
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.`,
261+
},
262+
240263
"enable_confidential_compute": {
241264
Type: schema.TypeBool,
242265
Optional: true,
@@ -2710,6 +2733,14 @@ func expandBootDisk(d *schema.ResourceData, config *transport_tpg.Config, projec
27102733
disk.InitializeParams.DiskSizeGb = int64(v.(int))
27112734
}
27122735

2736+
if v, ok := d.GetOk("boot_disk.0.initialize_params.0.provisioned_iops"); ok {
2737+
disk.InitializeParams.ProvisionedIops = int64(v.(int))
2738+
}
2739+
2740+
if v, ok := d.GetOk("boot_disk.0.initialize_params.0.provisioned_throughput"); ok {
2741+
disk.InitializeParams.ProvisionedThroughput = int64(v.(int))
2742+
}
2743+
27132744
if v, ok := d.GetOk("boot_disk.0.initialize_params.0.enable_confidential_compute"); ok {
27142745
disk.InitializeParams.EnableConfidentialCompute = v.(bool)
27152746
}
@@ -2779,6 +2810,8 @@ func flattenBootDisk(d *schema.ResourceData, disk *compute.AttachedDisk, config
27792810
"size": diskDetails.SizeGb,
27802811
"labels": diskDetails.Labels,
27812812
"resource_manager_tags": d.Get("boot_disk.0.initialize_params.0.resource_manager_tags"),
2813+
"provisioned_iops": diskDetails.ProvisionedIops,
2814+
"provisioned_throughput": diskDetails.ProvisionedThroughput,
27822815
"enable_confidential_compute": diskDetails.EnableConfidentialCompute,
27832816
}}
27842817
}

google-beta/services/compute/resource_compute_instance_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,29 @@ func TestAccComputeInstance_confidentialHyperDiskBootDisk(t *testing.T) {
18191819
})
18201820
}
18211821

1822+
func TestAccComputeInstance_hyperdiskBootDisk_provisioned_iops_throughput(t *testing.T) {
1823+
t.Parallel()
1824+
1825+
context := map[string]interface{}{
1826+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
1827+
"zone": "us-central1-a",
1828+
"provisioned_iops": 12000,
1829+
"provisioned_throughput": 200,
1830+
}
1831+
1832+
acctest.VcrTest(t, resource.TestCase{
1833+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1834+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1835+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
1836+
Steps: []resource.TestStep{
1837+
{
1838+
Config: testAccComputeInstanceHyperDiskBootDiskProvisionedIopsThroughput(context),
1839+
},
1840+
computeInstanceImportStep(context["zone"].(string), context["instance_name"].(string), []string{"allow_stopping_for_update"}),
1841+
},
1842+
})
1843+
}
1844+
18221845
func TestAccComputeInstance_enableDisplay(t *testing.T) {
18231846
t.Parallel()
18241847

@@ -6911,6 +6934,37 @@ resource "google_compute_instance" "foobar" {
69116934
`, context)
69126935
}
69136936

6937+
func testAccComputeInstanceHyperDiskBootDiskProvisionedIopsThroughput(context map[string]interface{}) string {
6938+
return acctest.Nprintf(`
6939+
data "google_compute_image" "my_image" {
6940+
family = "ubuntu-2204-lts"
6941+
project = "ubuntu-os-cloud"
6942+
}
6943+
6944+
data "google_project" "project" {}
6945+
6946+
resource "google_compute_instance" "foobar" {
6947+
name = "%{instance_name}"
6948+
machine_type = "h3-standard-88"
6949+
zone = "%{zone}"
6950+
6951+
boot_disk {
6952+
initialize_params {
6953+
image = data.google_compute_image.my_image.self_link
6954+
provisioned_iops = %{provisioned_iops}
6955+
provisioned_throughput = %{provisioned_throughput}
6956+
type = "hyperdisk-balanced"
6957+
size = 100
6958+
}
6959+
}
6960+
6961+
network_interface {
6962+
network = "default"
6963+
}
6964+
}
6965+
`, context)
6966+
}
6967+
69146968
func testAccComputeInstance_enableDisplay(instance string) string {
69156969
return fmt.Sprintf(`
69166970
data "google_compute_image" "my_image" {

website/docs/r/compute_instance.html.markdown

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ is desired, you will need to modify your state file manually using
249249

250250
* `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.
251251

252+
* `provisioned_iops` - (Optional) Indicates how many IOPS to provision for the disk.
253+
This sets the number of I/O operations per second that the disk can handle.
254+
Values must be between 10,000 and 120,000. For more details,see the
255+
[Extreme persistent disk documentation](https://cloud.google.com/compute/docs/disks/extreme-persistent-disk).
256+
Note: Updating currently is only supported for hyperdisk skus via disk update
257+
api/gcloud without the need to delete and recreate the disk, hyperdisk allows
258+
for an update of IOPS every 4 hours. To update your hyperdisk more frequently,
259+
you'll need to manually delete and recreate it.
260+
261+
* `provisioned_throughput` - (Optional) Indicates how much throughput to provision for the disk.
262+
This sets the number of throughput mb per second that the disk can handle.
263+
Values must be between 1 and 7,124. Note: Updating currently is only supported
264+
for hyperdisk skus via disk update api/gcloud without the need to delete and
265+
recreate the disk, hyperdisk allows for an update of throughput every 4 hours.
266+
To update your hyperdisk more frequently, you'll need to manually delete and recreate it.
267+
252268
<a name="nested_scratch_disk"></a>The `scratch_disk` block supports:
253269

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

0 commit comments

Comments
 (0)