Skip to content

Commit

Permalink
Network queue count support (#5438) (#3857)
Browse files Browse the repository at this point in the history
* Add queue_number

* Add network queue

* Remove update test, add to instance template

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Nov 16, 2021
1 parent ea3470c commit 1fd2251
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/5438.txt
Original file line number Diff line number Diff line change
@@ -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`
```
2 changes: 2 additions & 0 deletions google-beta/compute_instance_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{})),
}
}
Expand Down
7 changes: 7 additions & 0 deletions google-beta/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions google-beta/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,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.`,
},
},
},
},
Expand Down
46 changes: 46 additions & 0 deletions google-beta/resource_compute_instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,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)
Expand Down Expand Up @@ -2632,3 +2654,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)
}
44 changes: 44 additions & 0 deletions google-beta/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,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()

Expand Down Expand Up @@ -6127,3 +6144,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)
}
2 changes: 2 additions & 0 deletions website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.


<a name="nested_access_config"></a>The `access_config` block supports:

Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/compute_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<a name="nested_access_config"></a>The `access_config` block supports:

* `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's
Expand Down

0 comments on commit 1fd2251

Please sign in to comment.