diff --git a/autogen/cluster_regional.tf b/autogen/cluster_regional.tf index d8b4840d5a..25774de5f0 100644 --- a/autogen/cluster_regional.tf +++ b/autogen/cluster_regional.tf @@ -169,6 +169,11 @@ resource "google_container_node_pool" "pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/autogen/cluster_zonal.tf b/autogen/cluster_zonal.tf index 08149ee831..a8ebfad575 100644 --- a/autogen/cluster_zonal.tf +++ b/autogen/cluster_zonal.tf @@ -170,6 +170,11 @@ resource "google_container_node_pool" "zonal_pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/cluster_regional.tf b/cluster_regional.tf index 124fd8b21b..3f6394ba4d 100644 --- a/cluster_regional.tf +++ b/cluster_regional.tf @@ -144,6 +144,11 @@ resource "google_container_node_pool" "pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/cluster_zonal.tf b/cluster_zonal.tf index 087ac258d7..a7ed1d07e1 100644 --- a/cluster_zonal.tf +++ b/cluster_zonal.tf @@ -145,6 +145,11 @@ resource "google_container_node_pool" "zonal_pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/examples/node_pool/main.tf b/examples/node_pool/main.tf index 83aebf7a2b..4aae6ae42a 100644 --- a/examples/node_pool/main.tf +++ b/examples/node_pool/main.tf @@ -19,12 +19,12 @@ locals { } provider "google" { - version = "~> 2.7.0" + version = "~> 2.9.0" region = "${var.region}" } provider "google-beta" { - version = "~> 2.7.0" + version = "~> 2.9.0" region = "${var.region}" } @@ -57,6 +57,8 @@ module "gke" { max_count = 2 disk_size_gb = 30 disk_type = "pd-standard" + accelerator_count = 1 + accelerator_type = "nvidia-tesla-p4" image_type = "COS" auto_repair = false service_account = "${var.compute_engine_service_account}" diff --git a/modules/beta-private-cluster/cluster_regional.tf b/modules/beta-private-cluster/cluster_regional.tf index 39c4e3a899..12552bca33 100644 --- a/modules/beta-private-cluster/cluster_regional.tf +++ b/modules/beta-private-cluster/cluster_regional.tf @@ -161,6 +161,11 @@ resource "google_container_node_pool" "pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/modules/beta-private-cluster/cluster_zonal.tf b/modules/beta-private-cluster/cluster_zonal.tf index 843821ca28..a1d5edf744 100644 --- a/modules/beta-private-cluster/cluster_zonal.tf +++ b/modules/beta-private-cluster/cluster_zonal.tf @@ -162,6 +162,11 @@ resource "google_container_node_pool" "zonal_pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/modules/beta-public-cluster/cluster_regional.tf b/modules/beta-public-cluster/cluster_regional.tf index 60601bd644..56fde5a2da 100644 --- a/modules/beta-public-cluster/cluster_regional.tf +++ b/modules/beta-public-cluster/cluster_regional.tf @@ -155,6 +155,11 @@ resource "google_container_node_pool" "pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/modules/beta-public-cluster/cluster_zonal.tf b/modules/beta-public-cluster/cluster_zonal.tf index 37a8f847a2..a7331edd92 100644 --- a/modules/beta-public-cluster/cluster_zonal.tf +++ b/modules/beta-public-cluster/cluster_zonal.tf @@ -156,6 +156,11 @@ resource "google_container_node_pool" "zonal_pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/modules/private-cluster/cluster_regional.tf b/modules/private-cluster/cluster_regional.tf index b5869e6b61..d52ca5e746 100644 --- a/modules/private-cluster/cluster_regional.tf +++ b/modules/private-cluster/cluster_regional.tf @@ -150,6 +150,11 @@ resource "google_container_node_pool" "pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/modules/private-cluster/cluster_zonal.tf b/modules/private-cluster/cluster_zonal.tf index d318acd764..4fe7d8f24e 100644 --- a/modules/private-cluster/cluster_zonal.tf +++ b/modules/private-cluster/cluster_zonal.tf @@ -151,6 +151,11 @@ resource "google_container_node_pool" "zonal_pools" { "${concat(var.node_pools_oauth_scopes["all"], var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}", ] + + guest_accelerator { + type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}" + count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}" + } } lifecycle { diff --git a/test/integration/node_pool/controls/gcloud.rb b/test/integration/node_pool/controls/gcloud.rb index 889facf27f..a9696c211a 100644 --- a/test/integration/node_pool/controls/gcloud.rb +++ b/test/integration/node_pool/controls/gcloud.rb @@ -16,6 +16,8 @@ location = attribute('location') cluster_name = attribute('cluster_name') +expected_accelerators_count = "1" +expected_accelerators_type = "nvidia-tesla-p4" control "gcloud" do title "Google Compute Engine GKE configuration" @@ -202,6 +204,18 @@ ) end + it "has the expected accelerators" do + expect(data['nodePools']).to include( + including( + "name" => "pool-02", + "config" => including( + "accelerators" => [{"acceleratorCount" => expected_accelerators_count, + "acceleratorType" => expected_accelerators_type}], + ), + ) + ) + end + it "has the expected disk size" do expect(data['nodePools']).to include( including(