Skip to content

Commit a1fe036

Browse files
lnesteroffgontech
authored andcommitted
added provisioned_throughput to instance_template and region_instance_template (GoogleCloudPlatform#11901)
1 parent 74f0e4d commit a1fe036

4 files changed

+130
-3
lines changed

mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl

+21-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,15 @@ func ResourceComputeInstanceTemplate() *schema.Resource {
178178
Optional: true,
179179
ForceNew: true,
180180
Computed: true,
181-
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).`,
181+
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.`,
182+
},
183+
184+
"provisioned_throughput": {
185+
Type: schema.TypeInt,
186+
Optional: true,
187+
ForceNew: true,
188+
Computed: true,
189+
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).`,
182190
},
183191

184192
"resource_manager_tags": {
@@ -1233,7 +1241,7 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
12331241
}
12341242
if v, ok := d.GetOk(prefix + ".source"); ok {
12351243
disk.Source = v.(string)
1236-
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "provisioned_iops", "source_image", "source_snapshot", "labels"}
1244+
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "provisioned_iops", "provisioned_throughput", "source_image", "source_snapshot", "labels"}
12371245
for _, conflict := range conflicts {
12381246
if _, ok := d.GetOk(prefix + "." + conflict); ok {
12391247
return nil, fmt.Errorf("Cannot use `source` with any of the fields in %s", conflicts)
@@ -1256,6 +1264,9 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
12561264
if v, ok := d.GetOk(prefix + ".provisioned_iops"); ok {
12571265
disk.InitializeParams.ProvisionedIops = int64(v.(int))
12581266
}
1267+
if v, ok := d.GetOk(prefix + ".provisioned_throughput"); ok {
1268+
disk.InitializeParams.ProvisionedThroughput = int64(v.(int))
1269+
}
12591270
if _, ok := d.GetOk(prefix + ".resource_manager_tags"); ok {
12601271
disk.InitializeParams.ResourceManagerTags = tpgresource.ExpandStringMap(d, prefix + ".resource_manager_tags")
12611272
}
@@ -1486,6 +1497,7 @@ type diskCharacteristics struct {
14861497
autoDelete bool
14871498
sourceImage string
14881499
provisionedIops string
1500+
provisionedThroughput string
14891501
}
14901502

14911503
func diskCharacteristicsFromMap(m map[string]interface{}) diskCharacteristics {
@@ -1520,6 +1532,12 @@ func diskCharacteristicsFromMap(m map[string]interface{}) diskCharacteristics {
15201532
// use strings to compare for simplicity.
15211533
dc.provisionedIops = fmt.Sprintf("%v", v)
15221534
}
1535+
1536+
if v := m["provisioned_throughput"]; v != nil {
1537+
// Terraform and GCP return ints as different types (int vs int64), so just
1538+
// use strings to compare for simplicity.
1539+
dc.provisionedThroughput = fmt.Sprintf("%v", v)
1540+
}
15231541

15241542
return dc
15251543
}
@@ -1545,6 +1563,7 @@ func flattenDisk(disk *compute.AttachedDisk, configDisk map[string]any, defaultP
15451563
}
15461564
diskMap["disk_type"] = disk.InitializeParams.DiskType
15471565
diskMap["provisioned_iops"] = disk.InitializeParams.ProvisionedIops
1566+
diskMap["provisioned_throughput"] = disk.InitializeParams.ProvisionedThroughput
15481567
diskMap["disk_name"] = disk.InitializeParams.DiskName
15491568
diskMap["labels"] = disk.InitializeParams.Labels
15501569
// The API does not return a disk size value for scratch disks. They are largely only one size,

mmv1/third_party/terraform/services/compute/resource_compute_instance_template_test.go.tmpl

+51
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,26 @@ func TestAccComputeInstanceTemplate_diskIops(t *testing.T) {
404404
})
405405
}
406406

407+
func TestAccComputeInstanceTemplate_diskIopsThroughput(t *testing.T) {
408+
t.Parallel()
409+
410+
acctest.VcrTest(t, resource.TestCase{
411+
PreCheck: func() { acctest.AccTestPreCheck(t) },
412+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
413+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
414+
Steps: []resource.TestStep{
415+
{
416+
Config: testAccComputeInstanceTemplate_diskIopsThroughput(acctest.RandString(t, 10)),
417+
},
418+
{
419+
ResourceName: "google_compute_instance_template.foobar",
420+
ImportState: true,
421+
ImportStateVerify: true,
422+
},
423+
},
424+
})
425+
}
426+
407427
func TestAccComputeInstanceTemplate_subnet_auto(t *testing.T) {
408428
t.Parallel()
409429

@@ -2922,6 +2942,37 @@ resource "google_compute_instance_template" "foobar" {
29222942
`, suffix)
29232943
}
29242944

2945+
func testAccComputeInstanceTemplate_diskIopsThroughput(suffix string) string {
2946+
return fmt.Sprintf(`
2947+
data "google_compute_image" "my_image" {
2948+
family = "debian-11"
2949+
project = "debian-cloud"
2950+
}
2951+
2952+
resource "google_compute_instance_template" "foobar" {
2953+
name = "tf-test-instance-template-%s"
2954+
machine_type = "e2-medium"
2955+
2956+
disk {
2957+
source_image = data.google_compute_image.my_image.self_link
2958+
auto_delete = true
2959+
disk_size_gb = 100
2960+
boot = true
2961+
disk_type = "hyperdisk-balanced"
2962+
provisioned_iops = 10000
2963+
provisioned_throughput = 1024
2964+
labels = {
2965+
foo = "bar"
2966+
}
2967+
}
2968+
2969+
network_interface {
2970+
network = "default"
2971+
}
2972+
}
2973+
`, suffix)
2974+
}
2975+
29252976
func testAccComputeInstanceTemplate_subnet_auto(network, suffix string) string {
29262977
return fmt.Sprintf(`
29272978
data "google_compute_image" "my_image" {

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template.go.tmpl

+9-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,15 @@ func ResourceComputeRegionInstanceTemplate() *schema.Resource {
155155
Optional: true,
156156
ForceNew: true,
157157
Computed: true,
158-
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).`,
158+
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.`,
159+
},
160+
161+
"provisioned_throughput": {
162+
Type: schema.TypeInt,
163+
Optional: true,
164+
ForceNew: true,
165+
Computed: true,
166+
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).`,
159167
},
160168

161169
"resource_manager_tags": {

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_test.go.tmpl

+49
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,26 @@ func TestAccComputeRegionInstanceTemplate_diskIops(t *testing.T) {
303303
})
304304
}
305305

306+
func TestAccComputeRegionInstanceTemplate_diskIopsThroughput(t *testing.T) {
307+
t.Parallel()
308+
309+
acctest.VcrTest(t, resource.TestCase{
310+
PreCheck: func() { acctest.AccTestPreCheck(t) },
311+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
312+
CheckDestroy: testAccCheckComputeRegionInstanceTemplateDestroyProducer(t),
313+
Steps: []resource.TestStep{
314+
{
315+
Config: testAccComputeRegionInstanceTemplate_diskIopsThroughput(acctest.RandString(t, 10)),
316+
},
317+
{
318+
ResourceName: "google_compute_region_instance_template.foobar",
319+
ImportState: true,
320+
ImportStateVerify: true,
321+
},
322+
},
323+
})
324+
}
325+
306326
func TestAccComputeRegionInstanceTemplate_subnet_auto(t *testing.T) {
307327
t.Parallel()
308328

@@ -2279,6 +2299,35 @@ resource "google_compute_region_instance_template" "foobar" {
22792299
`, suffix)
22802300
}
22812301

2302+
func testAccComputeRegionInstanceTemplate_diskIopsThroughput(suffix string) string {
2303+
return fmt.Sprintf(`
2304+
data "google_compute_image" "my_image" {
2305+
family = "debian-11"
2306+
project = "debian-cloud"
2307+
}
2308+
2309+
resource "google_compute_region_instance_template" "foobar" {
2310+
name = "tf-test-instance-template-%s"
2311+
machine_type = "e2-medium"
2312+
region = "us-central1"
2313+
2314+
disk {
2315+
source_image = data.google_compute_image.my_image.self_link
2316+
auto_delete = true
2317+
disk_size_gb = 100
2318+
boot = true
2319+
disk_type = "hyperdisk-balanced"
2320+
provisioned_iops = 10000
2321+
provisioned_throughput = 1024
2322+
}
2323+
2324+
network_interface {
2325+
network = "default"
2326+
}
2327+
}
2328+
`, suffix)
2329+
}
2330+
22822331
func testAccComputeRegionInstanceTemplate_subnet_auto(network, suffix string) string {
22832332
return fmt.Sprintf(`
22842333
data "google_compute_image" "my_image" {

0 commit comments

Comments
 (0)