From 0148da3fc9767054cf4bdfea9bcc3d918437cb15 Mon Sep 17 00:00:00 2001 From: joelkattapuram <46967875+joelkattapuram@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:22:01 -0700 Subject: [PATCH] Add support for boost configs in workstations configs (#10176) * add boostConfig workstationConfig * add boostConfig workstationConfig * link example * remove * update descriptions and add update test * update machine type * fix update test --- .../workstations/WorkstationConfig.yaml | 39 +++++++++ .../examples/workstation_config_boost.tf.erb | 56 +++++++++++++ ...orkstations_workstation_config_test.go.erb | 79 +++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 mmv1/templates/terraform/examples/workstation_config_boost.tf.erb diff --git a/mmv1/products/workstations/WorkstationConfig.yaml b/mmv1/products/workstations/WorkstationConfig.yaml index 39fada27bca8..65a868209b9a 100644 --- a/mmv1/products/workstations/WorkstationConfig.yaml +++ b/mmv1/products/workstations/WorkstationConfig.yaml @@ -108,6 +108,13 @@ examples: vars: workstation_cluster_name: 'workstation-cluster' workstation_config_name: 'workstation-config' + - !ruby/object:Provider::Terraform::Examples + name: 'workstation_config_boost' + min_version: beta + primary_resource_id: 'default' + vars: + workstation_cluster_name: 'workstation-cluster' + workstation_config_name: 'workstation-config' - !ruby/object:Provider::Terraform::Examples name: 'workstation_config_encryption_key' min_version: beta @@ -213,6 +220,7 @@ properties: - 'host.gceInstance.shieldedInstanceConfig.enableIntegrityMonitoring' - 'host.gceInstance.confidentialInstanceConfig.enableConfidentialCompute' - 'host.gceInstance.accelerators' + - 'host.gceInstance.boostConfigs' - 'host.gceInstance.disableSsh' properties: - !ruby/object:Api::Type::NestedObject @@ -319,6 +327,37 @@ properties: description: | Number of accelerator cards exposed to the instance. required: true + - !ruby/object:Api::Type::Array + name: 'boostConfigs' + description: | + A list of the boost configurations that workstations created using this workstation configuration are allowed to use. + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::String + name: 'id' + description: | + The id to be used for the boost config. + required: true + - !ruby/object:Api::Type::String + name: 'machineType' + description: | + The type of machine that boosted VM instances will useā€”for example, e2-standard-4. For more information about machine types that Cloud Workstations supports, see the list of available machine types https://cloud.google.com/workstations/docs/available-machine-types. Defaults to e2-standard-4. + - !ruby/object:Api::Type::Array + name: 'accelerators' + description: | + An accelerator card attached to the boost instance. + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::String + name: 'type' + description: | + Type of accelerator resource to attach to the instance, for example, "nvidia-tesla-p100". + required: true + - !ruby/object:Api::Type::Integer + name: 'count' + description: | + Number of accelerator cards exposed to the instance. + required: true - !ruby/object:Api::Type::Array name: 'persistentDirectories' description: | diff --git a/mmv1/templates/terraform/examples/workstation_config_boost.tf.erb b/mmv1/templates/terraform/examples/workstation_config_boost.tf.erb new file mode 100644 index 000000000000..d498c3eb1281 --- /dev/null +++ b/mmv1/templates/terraform/examples/workstation_config_boost.tf.erb @@ -0,0 +1,56 @@ +resource "google_compute_network" "default" { + provider = google-beta + name = "<%= ctx[:vars]['workstation_cluster_name'] %>" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "default" { + provider = google-beta + name = "<%= ctx[:vars]['workstation_cluster_name'] %>" + ip_cidr_range = "10.0.0.0/24" + region = "us-central1" + network = google_compute_network.default.name +} + +resource "google_workstations_workstation_cluster" "<%= ctx[:primary_resource_id] %>" { + provider = google-beta + workstation_cluster_id = "<%= ctx[:vars]['workstation_cluster_name'] %>" + network = google_compute_network.default.id + subnetwork = google_compute_subnetwork.default.id + location = "us-central1" + + labels = { + "label" = "key" + } + + annotations = { + label-one = "value-one" + } +} + +resource "google_workstations_workstation_config" "<%= ctx[:primary_resource_id] %>" { + provider = google-beta + workstation_config_id = "<%= ctx[:vars]['workstation_config_name'] %>" + workstation_cluster_id = google_workstations_workstation_cluster.<%= ctx[:primary_resource_id] %>.workstation_cluster_id + location = "us-central1" + + host { + gce_instance { + machine_type = "e2-standard-4" + boot_disk_size_gb = 35 + disable_public_ip_addresses = true + boost_configs { + id = "boost-1" + machine_type = "n1-standard-2" + accelerators { + type = "nvidia-tesla-t4" + count = "1" + } + } + boost_configs { + id = "boost-1" + machine_type = "e2-standard-2" + } + } + } +} diff --git a/mmv1/third_party/terraform/services/workstations/resource_workstations_workstation_config_test.go.erb b/mmv1/third_party/terraform/services/workstations/resource_workstations_workstation_config_test.go.erb index e29069d6ab11..10839661da72 100644 --- a/mmv1/third_party/terraform/services/workstations/resource_workstations_workstation_config_test.go.erb +++ b/mmv1/third_party/terraform/services/workstations/resource_workstations_workstation_config_test.go.erb @@ -476,6 +476,80 @@ func testAccWorkstationsWorkstationConfig_serviceAccount(context map[string]inte `, context) } +func TestAccWorkstationsWorkstationConfig_boost(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + CheckDestroy: testAccCheckWorkstationsWorkstationConfigDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccWorkstationsWorkstationConfig_boost(context), + }, + { + ResourceName: "google_workstations_workstation_cluster.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag"}, + }, + }, + }) +} + +func testAccWorkstationsWorkstationConfig_boost(context map[string]interface{}) string { + return acctest.Nprintf(` + resource "google_compute_network" "default" { + provider = google-beta + name = "tf-test-workstation-cluster%{random_suffix}" + auto_create_subnetworks = false + } + + resource "google_compute_subnetwork" "default" { + provider = google-beta + name = "tf-test-workstation-cluster%{random_suffix}" + ip_cidr_range = "10.0.0.0/24" + region = "us-central1" + network = google_compute_network.default.name + } + + resource "google_workstations_workstation_cluster" "default" { + provider = google-beta + workstation_cluster_id = "tf-test-workstation-cluster%{random_suffix}" + network = google_compute_network.default.id + subnetwork = google_compute_subnetwork.default.id + location = "us-central1" + } + + resource "google_workstations_workstation_config" "default" { + provider = google-beta + workstation_config_id = "tf-test-workstation-config%{random_suffix}" + workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id + location = "us-central1" + host { + gce_instance { + boost_configs { + id = "boost-1" + machine_type = "n1-standard-2" + accelerators { + type = "nvidia-tesla-t4" + count = 1 + } + } + boost_configs { + id = "boost-1" + machine_type = "e2-standard-2" + } + } + } + } +`, context) +} + func TestAccWorkstationsWorkstationConfig_disableTcpConnections(t *testing.T) { t.Parallel() @@ -886,6 +960,11 @@ resource "google_workstations_workstation_config" "default" { confidential_instance_config { enable_confidential_compute = true } + + boost_configs { + id = "boost-1" + machine_type = "n2d-standard-2" + } } } }