Skip to content

Commit

Permalink
Add disk.provisioned_iops to compute_instance_template
Browse files Browse the repository at this point in the history
  • Loading branch information
roaks3 committed Aug 3, 2023
1 parent 60bd90b commit 86f8786
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ func ResourceComputeInstanceTemplate() *schema.Resource {
Description: `A set of key/value label pairs to assign to disks,`,
},

"provisioned_iops": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Computed: true,
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).`,
},

"source_image": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1102,7 +1110,7 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
}
if v, ok := d.GetOk(prefix + ".source"); ok {
disk.Source = v.(string)
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "source_image", "source_snapshot", "labels"}
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "provisioned_iops", "source_image", "source_snapshot", "labels"}
for _, conflict := range conflicts {
if _, ok := d.GetOk(prefix + "." + conflict); ok {
return nil, fmt.Errorf("Cannot use `source` with any of the fields in %s", conflicts)
Expand All @@ -1122,6 +1130,9 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
if v, ok := d.GetOk(prefix + ".disk_type"); ok {
disk.InitializeParams.DiskType = v.(string)
}
if v, ok := d.GetOk(prefix + ".provisioned_iops"); ok {
disk.InitializeParams.ProvisionedIops = int64(v.(int))
}

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

Expand Down Expand Up @@ -1378,6 +1389,7 @@ func flattenDisk(disk *compute.AttachedDisk, configDisk map[string]any, defaultP
diskMap["source_image"] = ""
}
diskMap["disk_type"] = disk.InitializeParams.DiskType
diskMap["provisioned_iops"] = disk.InitializeParams.ProvisionedIops
diskMap["disk_name"] = disk.InitializeParams.DiskName
diskMap["labels"] = disk.InitializeParams.Labels
// The API does not return a disk size value for scratch disks. They are largely only one size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,26 @@ func TestAccComputeInstanceTemplate_regionDisks(t *testing.T) {
})
}

func TestAccComputeInstanceTemplate_diskIops(t *testing.T) {
t.Parallel()

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceTemplate_diskIops(acctest.RandString(t, 10)),
},
{
ResourceName: "google_compute_instance_template.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccComputeInstanceTemplate_subnet_auto(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -2227,6 +2247,35 @@ resource "google_compute_instance_template" "foobar" {
`, suffix, suffix)
}

func testAccComputeInstanceTemplate_diskIops(suffix string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}

resource "google_compute_instance_template" "foobar" {
name = "tf-test-instance-template-%s"
machine_type = "e2-medium"

disk {
source_image = data.google_compute_image.my_image.self_link
auto_delete = true
disk_size_gb = 100
boot = true
provisioned_iops = 10000
labels = {
foo = "bar"
}
}

network_interface {
network = "default"
}
}
`, suffix)
}

func testAccComputeInstanceTemplate_subnet_auto(network, suffix string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down

0 comments on commit 86f8786

Please sign in to comment.