Skip to content

Commit 00e0ab8

Browse files
added provisioned_throughput to instance_template and region_instance_template (#11901) (#8405)
[upstream:5e938c69ed56e76d72b82692706160e17719e611] Signed-off-by: Modular Magician <[email protected]>
1 parent 4e6e2e4 commit 00e0ab8

5 files changed

+142
-9
lines changed

.changelog/11901.txt

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

google-beta/services/compute/resource_compute_instance_template.go

+27-8
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,15 @@ func ResourceComputeInstanceTemplate() *schema.Resource {
173173
Optional: true,
174174
ForceNew: true,
175175
Computed: true,
176-
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).`,
176+
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. For more details, see the [Extreme persistent disk documentation](https://cloud.google.com/compute/docs/disks/extreme-persistent-disk) or the [Hyperdisk documentation](https://cloud.google.com/compute/docs/disks/hyperdisks) depending on the selected disk_type.`,
177+
},
178+
179+
"provisioned_throughput": {
180+
Type: schema.TypeInt,
181+
Optional: true,
182+
ForceNew: true,
183+
Computed: true,
184+
Description: `Indicates how much throughput to provision for the disk, in MB/s. This sets the amount of data that can be read or written from the disk per second. Values must greater than or equal to 1. For more details, see the [Hyperdisk documentation](https://cloud.google.com/compute/docs/disks/hyperdisks).`,
177185
},
178186

179187
"resource_manager_tags": {
@@ -1220,7 +1228,7 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
12201228
}
12211229
if v, ok := d.GetOk(prefix + ".source"); ok {
12221230
disk.Source = v.(string)
1223-
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "provisioned_iops", "source_image", "source_snapshot", "labels"}
1231+
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "provisioned_iops", "provisioned_throughput", "source_image", "source_snapshot", "labels"}
12241232
for _, conflict := range conflicts {
12251233
if _, ok := d.GetOk(prefix + "." + conflict); ok {
12261234
return nil, fmt.Errorf("Cannot use `source` with any of the fields in %s", conflicts)
@@ -1243,6 +1251,9 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
12431251
if v, ok := d.GetOk(prefix + ".provisioned_iops"); ok {
12441252
disk.InitializeParams.ProvisionedIops = int64(v.(int))
12451253
}
1254+
if v, ok := d.GetOk(prefix + ".provisioned_throughput"); ok {
1255+
disk.InitializeParams.ProvisionedThroughput = int64(v.(int))
1256+
}
12461257
if _, ok := d.GetOk(prefix + ".resource_manager_tags"); ok {
12471258
disk.InitializeParams.ResourceManagerTags = tpgresource.ExpandStringMap(d, prefix+".resource_manager_tags")
12481259
}
@@ -1461,12 +1472,13 @@ func resourceComputeInstanceTemplateUpdate(d *schema.ResourceData, meta interfac
14611472
}
14621473

14631474
type diskCharacteristics struct {
1464-
mode string
1465-
diskType string
1466-
diskSizeGb string
1467-
autoDelete bool
1468-
sourceImage string
1469-
provisionedIops string
1475+
mode string
1476+
diskType string
1477+
diskSizeGb string
1478+
autoDelete bool
1479+
sourceImage string
1480+
provisionedIops string
1481+
provisionedThroughput string
14701482
}
14711483

14721484
func diskCharacteristicsFromMap(m map[string]interface{}) diskCharacteristics {
@@ -1502,6 +1514,12 @@ func diskCharacteristicsFromMap(m map[string]interface{}) diskCharacteristics {
15021514
dc.provisionedIops = fmt.Sprintf("%v", v)
15031515
}
15041516

1517+
if v := m["provisioned_throughput"]; v != nil {
1518+
// Terraform and GCP return ints as different types (int vs int64), so just
1519+
// use strings to compare for simplicity.
1520+
dc.provisionedThroughput = fmt.Sprintf("%v", v)
1521+
}
1522+
15051523
return dc
15061524
}
15071525

@@ -1525,6 +1543,7 @@ func flattenDisk(disk *compute.AttachedDisk, configDisk map[string]any, defaultP
15251543
}
15261544
diskMap["disk_type"] = disk.InitializeParams.DiskType
15271545
diskMap["provisioned_iops"] = disk.InitializeParams.ProvisionedIops
1546+
diskMap["provisioned_throughput"] = disk.InitializeParams.ProvisionedThroughput
15281547
diskMap["disk_name"] = disk.InitializeParams.DiskName
15291548
diskMap["labels"] = disk.InitializeParams.Labels
15301549
// 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

+51
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,26 @@ func TestAccComputeInstanceTemplate_diskIops(t *testing.T) {
393393
})
394394
}
395395

396+
func TestAccComputeInstanceTemplate_diskIopsThroughput(t *testing.T) {
397+
t.Parallel()
398+
399+
acctest.VcrTest(t, resource.TestCase{
400+
PreCheck: func() { acctest.AccTestPreCheck(t) },
401+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
402+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
403+
Steps: []resource.TestStep{
404+
{
405+
Config: testAccComputeInstanceTemplate_diskIopsThroughput(acctest.RandString(t, 10)),
406+
},
407+
{
408+
ResourceName: "google_compute_instance_template.foobar",
409+
ImportState: true,
410+
ImportStateVerify: true,
411+
},
412+
},
413+
})
414+
}
415+
396416
func TestAccComputeInstanceTemplate_subnet_auto(t *testing.T) {
397417
t.Parallel()
398418

@@ -2886,6 +2906,37 @@ resource "google_compute_instance_template" "foobar" {
28862906
`, suffix)
28872907
}
28882908

2909+
func testAccComputeInstanceTemplate_diskIopsThroughput(suffix string) string {
2910+
return fmt.Sprintf(`
2911+
data "google_compute_image" "my_image" {
2912+
family = "debian-11"
2913+
project = "debian-cloud"
2914+
}
2915+
2916+
resource "google_compute_instance_template" "foobar" {
2917+
name = "tf-test-instance-template-%s"
2918+
machine_type = "e2-medium"
2919+
2920+
disk {
2921+
source_image = data.google_compute_image.my_image.self_link
2922+
auto_delete = true
2923+
disk_size_gb = 100
2924+
boot = true
2925+
disk_type = "hyperdisk-balanced"
2926+
provisioned_iops = 10000
2927+
provisioned_throughput = 1024
2928+
labels = {
2929+
foo = "bar"
2930+
}
2931+
}
2932+
2933+
network_interface {
2934+
network = "default"
2935+
}
2936+
}
2937+
`, suffix)
2938+
}
2939+
28892940
func testAccComputeInstanceTemplate_subnet_auto(network, suffix string) string {
28902941
return fmt.Sprintf(`
28912942
data "google_compute_image" "my_image" {

google-beta/services/compute/resource_compute_region_instance_template.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,15 @@ func ResourceComputeRegionInstanceTemplate() *schema.Resource {
152152
Optional: true,
153153
ForceNew: true,
154154
Computed: true,
155-
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).`,
155+
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. For more details, see the [Extreme persistent disk documentation](https://cloud.google.com/compute/docs/disks/extreme-persistent-disk) or the [Hyperdisk documentation](https://cloud.google.com/compute/docs/disks/hyperdisks) depending on the selected disk_type.`,
156+
},
157+
158+
"provisioned_throughput": {
159+
Type: schema.TypeInt,
160+
Optional: true,
161+
ForceNew: true,
162+
Computed: true,
163+
Description: `Indicates how much throughput to provision for the disk, in MB/s. This sets the amount of data that can be read or written from the disk per second. Values must greater than or equal to 1. For more details, see the [Hyperdisk documentation](https://cloud.google.com/compute/docs/disks/hyperdisks).`,
156164
},
157165

158166
"resource_manager_tags": {

google-beta/services/compute/resource_compute_region_instance_template_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,26 @@ func TestAccComputeRegionInstanceTemplate_diskIops(t *testing.T) {
298298
})
299299
}
300300

301+
func TestAccComputeRegionInstanceTemplate_diskIopsThroughput(t *testing.T) {
302+
t.Parallel()
303+
304+
acctest.VcrTest(t, resource.TestCase{
305+
PreCheck: func() { acctest.AccTestPreCheck(t) },
306+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
307+
CheckDestroy: testAccCheckComputeRegionInstanceTemplateDestroyProducer(t),
308+
Steps: []resource.TestStep{
309+
{
310+
Config: testAccComputeRegionInstanceTemplate_diskIopsThroughput(acctest.RandString(t, 10)),
311+
},
312+
{
313+
ResourceName: "google_compute_region_instance_template.foobar",
314+
ImportState: true,
315+
ImportStateVerify: true,
316+
},
317+
},
318+
})
319+
}
320+
301321
func TestAccComputeRegionInstanceTemplate_subnet_auto(t *testing.T) {
302322
t.Parallel()
303323

@@ -2260,6 +2280,35 @@ resource "google_compute_region_instance_template" "foobar" {
22602280
`, suffix)
22612281
}
22622282

2283+
func testAccComputeRegionInstanceTemplate_diskIopsThroughput(suffix string) string {
2284+
return fmt.Sprintf(`
2285+
data "google_compute_image" "my_image" {
2286+
family = "debian-11"
2287+
project = "debian-cloud"
2288+
}
2289+
2290+
resource "google_compute_region_instance_template" "foobar" {
2291+
name = "tf-test-instance-template-%s"
2292+
machine_type = "e2-medium"
2293+
region = "us-central1"
2294+
2295+
disk {
2296+
source_image = data.google_compute_image.my_image.self_link
2297+
auto_delete = true
2298+
disk_size_gb = 100
2299+
boot = true
2300+
disk_type = "hyperdisk-balanced"
2301+
provisioned_iops = 10000
2302+
provisioned_throughput = 1024
2303+
}
2304+
2305+
network_interface {
2306+
network = "default"
2307+
}
2308+
}
2309+
`, suffix)
2310+
}
2311+
22632312
func testAccComputeRegionInstanceTemplate_subnet_auto(network, suffix string) string {
22642313
return fmt.Sprintf(`
22652314
data "google_compute_image" "my_image" {

0 commit comments

Comments
 (0)