Skip to content

Commit e35bc23

Browse files
Add disk.provisioned_iops to compute_instance_template (#8528) (#15506)
* Add disk.provisioned_iops to compute_instance_template * Add to region template as well * Add provisioned_iops to disk characteristics that are used for array ordering Signed-off-by: Modular Magician <[email protected]>
1 parent cd5e549 commit e35bc23

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

.changelog/8528.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
compute: added `disk.provisioned_iops` to `google_compute_instance_template`
3+
```
4+
```release-note:enhancement
5+
compute: added `disk.provisioned_iops` to `google_compute_region_instance_template`
6+
```

google/services/compute/resource_compute_instance_template.go

+26-6
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ func ResourceComputeInstanceTemplate() *schema.Resource {
161161
Description: `A set of key/value label pairs to assign to disks,`,
162162
},
163163

164+
"provisioned_iops": {
165+
Type: schema.TypeInt,
166+
Optional: true,
167+
ForceNew: true,
168+
Computed: true,
169+
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. For more details, see the [Extreme persistent disk documentation](https://cloud.google.com/compute/docs/disks/extreme-persistent-disk).`,
170+
},
171+
164172
"source_image": {
165173
Type: schema.TypeString,
166174
Optional: true,
@@ -1040,7 +1048,7 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
10401048
}
10411049
if v, ok := d.GetOk(prefix + ".source"); ok {
10421050
disk.Source = v.(string)
1043-
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "source_image", "source_snapshot", "labels"}
1051+
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "provisioned_iops", "source_image", "source_snapshot", "labels"}
10441052
for _, conflict := range conflicts {
10451053
if _, ok := d.GetOk(prefix + "." + conflict); ok {
10461054
return nil, fmt.Errorf("Cannot use `source` with any of the fields in %s", conflicts)
@@ -1060,6 +1068,9 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
10601068
if v, ok := d.GetOk(prefix + ".disk_type"); ok {
10611069
disk.InitializeParams.DiskType = v.(string)
10621070
}
1071+
if v, ok := d.GetOk(prefix + ".provisioned_iops"); ok {
1072+
disk.InitializeParams.ProvisionedIops = int64(v.(int))
1073+
}
10631074

10641075
disk.InitializeParams.Labels = tpgresource.ExpandStringMap(d, prefix+".labels")
10651076

@@ -1256,11 +1267,12 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
12561267
}
12571268

12581269
type diskCharacteristics struct {
1259-
mode string
1260-
diskType string
1261-
diskSizeGb string
1262-
autoDelete bool
1263-
sourceImage string
1270+
mode string
1271+
diskType string
1272+
diskSizeGb string
1273+
autoDelete bool
1274+
sourceImage string
1275+
provisionedIops string
12641276
}
12651277

12661278
func diskCharacteristicsFromMap(m map[string]interface{}) diskCharacteristics {
@@ -1289,6 +1301,13 @@ func diskCharacteristicsFromMap(m map[string]interface{}) diskCharacteristics {
12891301
if v := m["source_image"]; v != nil {
12901302
dc.sourceImage = v.(string)
12911303
}
1304+
1305+
if v := m["provisioned_iops"]; v != nil {
1306+
// Terraform and GCP return ints as different types (int vs int64), so just
1307+
// use strings to compare for simplicity.
1308+
dc.provisionedIops = fmt.Sprintf("%v", v)
1309+
}
1310+
12921311
return dc
12931312
}
12941313

@@ -1311,6 +1330,7 @@ func flattenDisk(disk *compute.AttachedDisk, configDisk map[string]any, defaultP
13111330
diskMap["source_image"] = ""
13121331
}
13131332
diskMap["disk_type"] = disk.InitializeParams.DiskType
1333+
diskMap["provisioned_iops"] = disk.InitializeParams.ProvisionedIops
13141334
diskMap["disk_name"] = disk.InitializeParams.DiskName
13151335
diskMap["labels"] = disk.InitializeParams.Labels
13161336
// The API does not return a disk size value for scratch disks. They are largely only one size,

google/services/compute/resource_compute_instance_template_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,26 @@ func TestAccComputeInstanceTemplate_regionDisks(t *testing.T) {
295295
})
296296
}
297297

298+
func TestAccComputeInstanceTemplate_diskIops(t *testing.T) {
299+
t.Parallel()
300+
301+
acctest.VcrTest(t, resource.TestCase{
302+
PreCheck: func() { acctest.AccTestPreCheck(t) },
303+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
304+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
305+
Steps: []resource.TestStep{
306+
{
307+
Config: testAccComputeInstanceTemplate_diskIops(acctest.RandString(t, 10)),
308+
},
309+
{
310+
ResourceName: "google_compute_instance_template.foobar",
311+
ImportState: true,
312+
ImportStateVerify: true,
313+
},
314+
},
315+
})
316+
}
317+
298318
func TestAccComputeInstanceTemplate_subnet_auto(t *testing.T) {
299319
t.Parallel()
300320

@@ -2000,6 +2020,35 @@ resource "google_compute_instance_template" "foobar" {
20002020
`, suffix, suffix)
20012021
}
20022022

2023+
func testAccComputeInstanceTemplate_diskIops(suffix string) string {
2024+
return fmt.Sprintf(`
2025+
data "google_compute_image" "my_image" {
2026+
family = "debian-11"
2027+
project = "debian-cloud"
2028+
}
2029+
2030+
resource "google_compute_instance_template" "foobar" {
2031+
name = "tf-test-instance-template-%s"
2032+
machine_type = "e2-medium"
2033+
2034+
disk {
2035+
source_image = data.google_compute_image.my_image.self_link
2036+
auto_delete = true
2037+
disk_size_gb = 100
2038+
boot = true
2039+
provisioned_iops = 10000
2040+
labels = {
2041+
foo = "bar"
2042+
}
2043+
}
2044+
2045+
network_interface {
2046+
network = "default"
2047+
}
2048+
}
2049+
`, suffix)
2050+
}
2051+
20032052
func testAccComputeInstanceTemplate_subnet_auto(network, suffix string) string {
20042053
return fmt.Sprintf(`
20052054
data "google_compute_image" "my_image" {

0 commit comments

Comments
 (0)