From a92aea2cc92c2e6f14e5f453fac134d65d5a438a Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 16 Nov 2021 22:28:54 +0000 Subject: [PATCH] Network queue count support (#5438) * Add queue_number * Add network queue * Remove update test, add to instance template Signed-off-by: Modular Magician --- .changelog/5438.txt | 3 ++ google/compute_instance_helpers.go | 2 + google/resource_compute_instance.go | 7 +++ google/resource_compute_instance_template.go | 6 +++ ...resource_compute_instance_template_test.go | 46 +++++++++++++++++++ google/resource_compute_instance_test.go | 44 ++++++++++++++++++ website/docs/r/compute_instance.html.markdown | 2 + .../r/compute_instance_template.html.markdown | 2 + 8 files changed, 112 insertions(+) create mode 100644 .changelog/5438.txt diff --git a/.changelog/5438.txt b/.changelog/5438.txt new file mode 100644 index 00000000000..59341151eae --- /dev/null +++ b/.changelog/5438.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: added support for `queue_count` to `google_compute_instance.network_interface` and `google_compute_instance_template.network_interface` +``` diff --git a/google/compute_instance_helpers.go b/google/compute_instance_helpers.go index 01936c073f3..08ccad1c270 100644 --- a/google/compute_instance_helpers.go +++ b/google/compute_instance_helpers.go @@ -199,6 +199,7 @@ func flattenNetworkInterfaces(d *schema.ResourceData, config *Config, networkInt "nic_type": iface.NicType, "stack_type": iface.StackType, "ipv6_access_config": flattenIpv6AccessConfigs(iface.Ipv6AccessConfigs), + "queue_count": iface.QueueCount, } // Instance template interfaces never have names, so they're absent // in the instance template network_interface schema. We want to use the @@ -279,6 +280,7 @@ func expandNetworkInterfaces(d TerraformResourceData, config *Config) ([]*comput AliasIpRanges: expandAliasIpRanges(data["alias_ip_range"].([]interface{})), NicType: data["nic_type"].(string), StackType: data["stack_type"].(string), + QueueCount: int64(data["queue_count"].(int)), Ipv6AccessConfigs: expandIpv6AccessConfigs(data["ipv6_access_config"].([]interface{})), } } diff --git a/google/resource_compute_instance.go b/google/resource_compute_instance.go index e4e6794b4cd..bd403f89f6b 100644 --- a/google/resource_compute_instance.go +++ b/google/resource_compute_instance.go @@ -395,6 +395,13 @@ func resourceComputeInstance() *schema.Resource { }, }, }, + + "queue_count": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Description: `The networking queue count that's specified by users for the network interface. Both Rx and Tx queues will be set to this number. It will be empty if not specified.`, + }, }, }, }, diff --git a/google/resource_compute_instance_template.go b/google/resource_compute_instance_template.go index 5e573c1ec82..9bf4371f9d5 100644 --- a/google/resource_compute_instance_template.go +++ b/google/resource_compute_instance_template.go @@ -426,6 +426,12 @@ func resourceComputeInstanceTemplate() *schema.Resource { }, }, }, + "queue_count": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Description: `The networking queue count that's specified by users for the network interface. Both Rx and Tx queues will be set to this number. It will be empty if not specified.`, + }, }, }, }, diff --git a/google/resource_compute_instance_template_test.go b/google/resource_compute_instance_template_test.go index 7ea2aa6f18b..230fd50526d 100644 --- a/google/resource_compute_instance_template_test.go +++ b/google/resource_compute_instance_template_test.go @@ -1031,6 +1031,28 @@ func TestAccComputeInstanceTemplate_nictype_update(t *testing.T) { }) } +func TestAccComputeInstanceTemplate_queueCount(t *testing.T) { + t.Parallel() + + var instanceTemplate compute.InstanceTemplate + var instanceTemplateName = fmt.Sprintf("tf-test-%s", randString(t, 10)) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeInstanceTemplate_queueCount(instanceTemplateName), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeInstanceTemplateExists( + t, "google_compute_instance_template.foobar", &instanceTemplate), + ), + }, + }, + }) +} + func testAccCheckComputeInstanceTemplateDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { config := googleProviderConfig(t) @@ -2588,3 +2610,27 @@ resource "google_compute_instance_template" "foobar" { } `, image, instance, nictype) } + +func testAccComputeInstanceTemplate_queueCount(instanceTemplateName string) string { + return fmt.Sprintf(` +data "google_compute_image" "my_image" { + family = "debian-9" + project = "debian-cloud" +} + +resource "google_compute_instance_template" "foobar" { + name = "%s" + machine_type = "e2-medium" + network_interface { + network = "default" + access_config {} + queue_count = 2 + } + disk { + source_image = data.google_compute_image.my_image.self_link + auto_delete = true + boot = true + } +} +`, instanceTemplateName) +} diff --git a/google/resource_compute_instance_test.go b/google/resource_compute_instance_test.go index 2dbe98b3212..0ed4d5a303d 100644 --- a/google/resource_compute_instance_test.go +++ b/google/resource_compute_instance_test.go @@ -2169,6 +2169,23 @@ func TestAccComputeInstance_subnetworkUpdate(t *testing.T) { }) } +func TestAccComputeInstance_queueCount(t *testing.T) { + t.Parallel() + instanceName := fmt.Sprintf("tf-test-%s", randString(t, 10)) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeInstance_queueCountSet(instanceName), + }, + computeInstanceImportStep("us-east1-d", instanceName, []string{"allow_stopping_for_update"}), + }, + }) +} + func TestComputeInstance_networkIPCustomizedDiff(t *testing.T) { t.Parallel() @@ -6041,3 +6058,30 @@ func testAccComputeInstance_subnetworkUpdateTwo(suffix, instance string) string } `, suffix, suffix, suffix, suffix, instance) } + +func testAccComputeInstance_queueCountSet(instance string) string { + return fmt.Sprintf(` +data "google_compute_image" "my_image" { + family = "debian-9" + project = "debian-cloud" +} + +resource "google_compute_instance" "foobar" { + name = "%s" + machine_type = "e2-medium" + zone = "us-east1-d" + allow_stopping_for_update = true + + boot_disk { + initialize_params { + image = data.google_compute_image.my_image.id + } + } + + network_interface { + network = "default" + queue_count = 2 + } +} +`, instance) +} diff --git a/website/docs/r/compute_instance.html.markdown b/website/docs/r/compute_instance.html.markdown index 95d40c677d9..c8c703a604b 100644 --- a/website/docs/r/compute_instance.html.markdown +++ b/website/docs/r/compute_instance.html.markdown @@ -304,6 +304,8 @@ is desired, you will need to modify your state file manually using Currently, only one IPv6 access config, DIRECT_IPV6, is supported. If there is no ipv6AccessConfig specified, then this instance will have no external IPv6 Internet access. Structure [documented below](#nested_ipv6_access_config). +* `queue_count` - (Optional) The networking queue count that's specified by users for the network interface. Both Rx and Tx queues will be set to this number. It will be empty if not specified. + The `access_config` block supports: diff --git a/website/docs/r/compute_instance_template.html.markdown b/website/docs/r/compute_instance_template.html.markdown index 7ab9ac2e534..59b39c3ec14 100644 --- a/website/docs/r/compute_instance_template.html.markdown +++ b/website/docs/r/compute_instance_template.html.markdown @@ -383,6 +383,8 @@ The `disk_encryption_key` block supports: Currently, only one IPv6 access config, DIRECT_IPV6, is supported. If there is no ipv6AccessConfig specified, then this instance will have no external IPv6 Internet access. Structure [documented below](#nested_ipv6_access_config). +* `queue_count` - (Optional) The networking queue count that's specified by users for the network interface. Both Rx and Tx queues will be set to this number. It will be empty if not specified. + The `access_config` block supports: * `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's