Skip to content

Commit a5f80e0

Browse files
Add disk.provisioned_iops to compute_instance_template (#8528) (#6071)
* 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 881ed02 commit a5f80e0

File tree

5 files changed

+136
-6
lines changed

5 files changed

+136
-6
lines changed

.changelog/8528.txt

Lines changed: 6 additions & 0 deletions
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-beta/services/compute/resource_compute_instance_template.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ func ResourceComputeInstanceTemplate() *schema.Resource {
163163
Description: `A set of key/value label pairs to assign to disks,`,
164164
},
165165

166+
"provisioned_iops": {
167+
Type: schema.TypeInt,
168+
Optional: true,
169+
ForceNew: true,
170+
Computed: true,
171+
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).`,
172+
},
173+
166174
"source_image": {
167175
Type: schema.TypeString,
168176
Optional: true,
@@ -1090,7 +1098,7 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
10901098
}
10911099
if v, ok := d.GetOk(prefix + ".source"); ok {
10921100
disk.Source = v.(string)
1093-
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "source_image", "source_snapshot", "labels"}
1101+
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "provisioned_iops", "source_image", "source_snapshot", "labels"}
10941102
for _, conflict := range conflicts {
10951103
if _, ok := d.GetOk(prefix + "." + conflict); ok {
10961104
return nil, fmt.Errorf("Cannot use `source` with any of the fields in %s", conflicts)
@@ -1110,6 +1118,9 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
11101118
if v, ok := d.GetOk(prefix + ".disk_type"); ok {
11111119
disk.InitializeParams.DiskType = v.(string)
11121120
}
1121+
if v, ok := d.GetOk(prefix + ".provisioned_iops"); ok {
1122+
disk.InitializeParams.ProvisionedIops = int64(v.(int))
1123+
}
11131124

11141125
disk.InitializeParams.Labels = tpgresource.ExpandStringMap(d, prefix+".labels")
11151126

@@ -1307,11 +1318,12 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
13071318
}
13081319

13091320
type diskCharacteristics struct {
1310-
mode string
1311-
diskType string
1312-
diskSizeGb string
1313-
autoDelete bool
1314-
sourceImage string
1321+
mode string
1322+
diskType string
1323+
diskSizeGb string
1324+
autoDelete bool
1325+
sourceImage string
1326+
provisionedIops string
13151327
}
13161328

13171329
func diskCharacteristicsFromMap(m map[string]interface{}) diskCharacteristics {
@@ -1340,6 +1352,13 @@ func diskCharacteristicsFromMap(m map[string]interface{}) diskCharacteristics {
13401352
if v := m["source_image"]; v != nil {
13411353
dc.sourceImage = v.(string)
13421354
}
1355+
1356+
if v := m["provisioned_iops"]; v != nil {
1357+
// Terraform and GCP return ints as different types (int vs int64), so just
1358+
// use strings to compare for simplicity.
1359+
dc.provisionedIops = fmt.Sprintf("%v", v)
1360+
}
1361+
13431362
return dc
13441363
}
13451364

@@ -1362,6 +1381,7 @@ func flattenDisk(disk *compute.AttachedDisk, configDisk map[string]any, defaultP
13621381
diskMap["source_image"] = ""
13631382
}
13641383
diskMap["disk_type"] = disk.InitializeParams.DiskType
1384+
diskMap["provisioned_iops"] = disk.InitializeParams.ProvisionedIops
13651385
diskMap["disk_name"] = disk.InitializeParams.DiskName
13661386
diskMap["labels"] = disk.InitializeParams.Labels
13671387
// The API does not return a disk size value for scratch disks. They are largely only one size,

google-beta/services/compute/resource_compute_instance_template_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,26 @@ func TestAccComputeInstanceTemplate_regionDisks(t *testing.T) {
330330
})
331331
}
332332

333+
func TestAccComputeInstanceTemplate_diskIops(t *testing.T) {
334+
t.Parallel()
335+
336+
acctest.VcrTest(t, resource.TestCase{
337+
PreCheck: func() { acctest.AccTestPreCheck(t) },
338+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
339+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
340+
Steps: []resource.TestStep{
341+
{
342+
Config: testAccComputeInstanceTemplate_diskIops(acctest.RandString(t, 10)),
343+
},
344+
{
345+
ResourceName: "google_compute_instance_template.foobar",
346+
ImportState: true,
347+
ImportStateVerify: true,
348+
},
349+
},
350+
})
351+
}
352+
333353
func TestAccComputeInstanceTemplate_subnet_auto(t *testing.T) {
334354
t.Parallel()
335355

@@ -2204,6 +2224,35 @@ resource "google_compute_instance_template" "foobar" {
22042224
`, suffix, suffix)
22052225
}
22062226

2227+
func testAccComputeInstanceTemplate_diskIops(suffix string) string {
2228+
return fmt.Sprintf(`
2229+
data "google_compute_image" "my_image" {
2230+
family = "debian-11"
2231+
project = "debian-cloud"
2232+
}
2233+
2234+
resource "google_compute_instance_template" "foobar" {
2235+
name = "tf-test-instance-template-%s"
2236+
machine_type = "e2-medium"
2237+
2238+
disk {
2239+
source_image = data.google_compute_image.my_image.self_link
2240+
auto_delete = true
2241+
disk_size_gb = 100
2242+
boot = true
2243+
provisioned_iops = 10000
2244+
labels = {
2245+
foo = "bar"
2246+
}
2247+
}
2248+
2249+
network_interface {
2250+
network = "default"
2251+
}
2252+
}
2253+
`, suffix)
2254+
}
2255+
22072256
func testAccComputeInstanceTemplate_subnet_auto(network, suffix string) string {
22082257
return fmt.Sprintf(`
22092258
data "google_compute_image" "my_image" {

google-beta/services/compute/resource_compute_region_instance_template.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ func ResourceComputeRegionInstanceTemplate() *schema.Resource {
143143
Description: `A set of key/value label pairs to assign to disks,`,
144144
},
145145

146+
"provisioned_iops": {
147+
Type: schema.TypeInt,
148+
Optional: true,
149+
ForceNew: true,
150+
Computed: true,
151+
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).`,
152+
},
153+
146154
"source_image": {
147155
Type: schema.TypeString,
148156
Optional: true,

google-beta/services/compute/resource_compute_region_instance_template_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,26 @@ func TestAccComputeRegionInstanceTemplate_regionDisks(t *testing.T) {
274274
})
275275
}
276276

277+
func TestAccComputeRegionInstanceTemplate_diskIops(t *testing.T) {
278+
t.Parallel()
279+
280+
acctest.VcrTest(t, resource.TestCase{
281+
PreCheck: func() { acctest.AccTestPreCheck(t) },
282+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
283+
CheckDestroy: testAccCheckComputeRegionInstanceTemplateDestroyProducer(t),
284+
Steps: []resource.TestStep{
285+
{
286+
Config: testAccComputeRegionInstanceTemplate_diskIops(acctest.RandString(t, 10)),
287+
},
288+
{
289+
ResourceName: "google_compute_region_instance_template.foobar",
290+
ImportState: true,
291+
ImportStateVerify: true,
292+
},
293+
},
294+
})
295+
}
296+
277297
func TestAccComputeRegionInstanceTemplate_subnet_auto(t *testing.T) {
278298
t.Parallel()
279299

@@ -2060,6 +2080,33 @@ resource "google_compute_region_instance_template" "foobar" {
20602080
`, suffix, suffix)
20612081
}
20622082

2083+
func testAccComputeRegionInstanceTemplate_diskIops(suffix string) string {
2084+
return fmt.Sprintf(`
2085+
data "google_compute_image" "my_image" {
2086+
family = "debian-11"
2087+
project = "debian-cloud"
2088+
}
2089+
2090+
resource "google_compute_region_instance_template" "foobar" {
2091+
name = "tf-test-instance-template-%s"
2092+
machine_type = "e2-medium"
2093+
region = "us-central1"
2094+
2095+
disk {
2096+
source_image = data.google_compute_image.my_image.self_link
2097+
auto_delete = true
2098+
disk_size_gb = 100
2099+
boot = true
2100+
provisioned_iops = 10000
2101+
}
2102+
2103+
network_interface {
2104+
network = "default"
2105+
}
2106+
}
2107+
`, suffix)
2108+
}
2109+
20632110
func testAccComputeRegionInstanceTemplate_subnet_auto(network, suffix string) string {
20642111
return fmt.Sprintf(`
20652112
data "google_compute_image" "my_image" {

0 commit comments

Comments
 (0)