diff --git a/.changelog/5789.txt b/.changelog/5789.txt new file mode 100644 index 00000000000..42a5ca056a6 --- /dev/null +++ b/.changelog/5789.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +container: add support for gvnic to `google_container_node_pool` +``` diff --git a/google/node_config.go b/google/node_config.go index 57c70d4ffe6..daa5285566a 100644 --- a/google/node_config.go +++ b/google/node_config.go @@ -123,6 +123,24 @@ func schemaNodeConfig() *schema.Schema { }, }, + "gvnic": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Description: `Enable or disable gvnic in the node pool.`, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enabled": { + Type: schema.TypeBool, + Required: true, + ForceNew: true, + Description: `Whether or not gvnic is enabled`, + }, + }, + }, + }, + "machine_type": { Type: schema.TypeString, Optional: true, @@ -336,6 +354,13 @@ func expandNodeConfig(v interface{}) *container.NodeConfig { } } + if v, ok := nodeConfig["gvnic"]; ok && len(v.([]interface{})) > 0 { + conf := v.([]interface{})[0].(map[string]interface{}) + nc.Gvnic = &container.VirtualNIC{ + Enabled: conf["enabled"].(bool), + } + } + if scopes, ok := nodeConfig["oauth_scopes"]; ok { scopesSet := scopes.(*schema.Set) scopes := make([]string, scopesSet.Len()) @@ -459,6 +484,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} { "guest_accelerator": flattenContainerGuestAccelerators(c.Accelerators), "local_ssd_count": c.LocalSsdCount, "gcfs_config": flattenGcfsConfig(c.GcfsConfig), + "gvnic": flattenGvnic(c.Gvnic), "service_account": c.ServiceAccount, "metadata": c.Metadata, "image_type": c.ImageType, @@ -513,6 +539,16 @@ func flattenGcfsConfig(c *container.GcfsConfig) []map[string]interface{} { return result } +func flattenGvnic(c *container.VirtualNIC) []map[string]interface{} { + result := []map[string]interface{}{} + if c != nil { + result = append(result, map[string]interface{}{ + "enabled": c.Enabled, + }) + } + return result +} + func flattenTaints(c []*container.NodeTaint) []map[string]interface{} { result := []map[string]interface{}{} for _, taint := range c { diff --git a/google/resource_container_node_pool_test.go b/google/resource_container_node_pool_test.go index ddfd5977033..fca60138d5a 100644 --- a/google/resource_container_node_pool_test.go +++ b/google/resource_container_node_pool_test.go @@ -714,6 +714,55 @@ resource "google_container_node_pool" "np" { `, cluster, np) } +func TestAccContainerNodePool_gvnic(t *testing.T) { + t.Parallel() + + cluster := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10)) + np := fmt.Sprintf("tf-test-nodepool-%s", randString(t, 10)) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccContainerNodePool_gvnic(cluster, np), + }, + { + ResourceName: "google_container_node_pool.np", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccContainerNodePool_gvnic(cluster, np string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "cluster" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = "1.19" +} + +resource "google_container_node_pool" "np" { + name = "%s" + location = "us-central1-a" + cluster = google_container_cluster.cluster.name + initial_node_count = 1 + + node_config { + machine_type = "n1-standard-8" + image_type = "COS_CONTAINERD" + gvnic { + enabled = true + } + } +} +`, cluster, np) +} + func testAccCheckContainerNodePoolDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { config := googleProviderConfig(t) diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 880514aadeb..b51f708072b 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -367,7 +367,7 @@ subnetwork in which the cluster's instances are launched. It can only be disabled if the nodes already do not have network policies enabled. Defaults to disabled; set `disabled = false` to enable. -* `gcp_filestore_csi_driver_config` - (Optional) The status of the Filestore CSI driver addon, +* `gcp_filestore_csi_driver_config` - (Optional) The status of the Filestore CSI driver addon, which allows the usage of filestore instance as volumes. It is disabled by default; set `enabled = true` to enable. @@ -649,6 +649,20 @@ gcfs_config { } ``` + +* `gvnic` - (Optional) Google Virtual NIC (gVNIC) is a virtual network interface. + Installing the gVNIC driver allows for more efficient traffic transmission across the Google network infrastructure. + gVNIC is an alternative to the virtIO-based ethernet driver. GKE nodes must use a Container-Optimized OS node image. + GKE node version 1.15.11-gke.15 or later + Structure is [documented below](#nested_gvnic). + + +```hcl +gvnic { + enabled = true +} +``` + * `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance. Structure [documented below](#nested_guest_accelerator). To support removal of guest_accelerators in Terraform 0.12 this field is an @@ -762,6 +776,10 @@ linux_node_config { * `enabled` (Required) - Whether or not the Google Container Filesystem (GCFS) is enabled +The `gvnic` block supports: + +* `enabled` (Required) - Whether or not the Google Virtual NIC (gVNIC) is enabled + The `guest_accelerator` block supports: * `type` (Required) - The accelerator type resource to expose to this instance. E.g. `nvidia-tesla-k80`. diff --git a/website/docs/r/container_node_pool.html.markdown b/website/docs/r/container_node_pool.html.markdown index e2dfe8a503f..6ce7d4ed649 100644 --- a/website/docs/r/container_node_pool.html.markdown +++ b/website/docs/r/container_node_pool.html.markdown @@ -148,7 +148,7 @@ cluster. with the specified prefix. Conflicts with `name`. * `node_config` - (Optional) Parameters used in creating the node pool. See - [google_container_cluster](container_cluster.html) for schema. + [google_container_cluster](container_cluster.html#nested_node_config) for schema. * `network_config` - (Optional) The network configuration of the pool. See [google_container_cluster](container_cluster.html) for schema.