From 1998693b8c5995559158dea83b1d5baf208bace0 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Fri, 21 Jun 2024 18:36:09 +0000 Subject: [PATCH 1/3] feat: added new field vm_tags to the workstation config --- mmv1/products/workstations/WorkstationConfig.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mmv1/products/workstations/WorkstationConfig.yaml b/mmv1/products/workstations/WorkstationConfig.yaml index ff575c7801f5..4e8bf6dbd8c3 100644 --- a/mmv1/products/workstations/WorkstationConfig.yaml +++ b/mmv1/products/workstations/WorkstationConfig.yaml @@ -73,6 +73,10 @@ examples: vars: workstation_cluster_name: 'workstation-cluster' workstation_config_name: 'workstation-config' + tag_key1: 'tag_key1' + tag_value1: 'tag_value1' + tag_key2: 'tag_key2' + tag_value2: 'tag_value2' - !ruby/object:Provider::Terraform::Examples name: 'workstation_config_container' min_version: beta @@ -222,6 +226,7 @@ properties: - 'host.gceInstance.accelerators' - 'host.gceInstance.boostConfigs' - 'host.gceInstance.disableSsh' + - 'host.gceInstance.vmTags' properties: - !ruby/object:Api::Type::NestedObject name: 'gceInstance' @@ -376,6 +381,14 @@ properties: description: | Number of accelerator cards exposed to the instance. required: true + - !ruby/object:Api::Type::KeyValuePairs + name: 'vmTags' + description: | + Resource manager tags to be bound to the VM instances backing the Workstations. + Tag keys and values have the same definition as + https://cloud.google.com/resource-manager/docs/tags/tags-overview + Keys must be in the format `tagKeys/{tag_key_id}`, and + values are in the format `tagValues/456`. - !ruby/object:Api::Type::Array name: 'persistentDirectories' description: | From c39c489e56883c7a24e3286d6eb4579885b7b2e9 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Tue, 25 Jun 2024 06:21:32 +0000 Subject: [PATCH 2/3] add tests --- .../workstations/WorkstationConfig.yaml | 2 - .../examples/workstation_config_basic.tf.erb | 21 +++++ ...orkstations_workstation_config_test.go.erb | 87 +++++++++++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/mmv1/products/workstations/WorkstationConfig.yaml b/mmv1/products/workstations/WorkstationConfig.yaml index 4e8bf6dbd8c3..83086c194d3b 100644 --- a/mmv1/products/workstations/WorkstationConfig.yaml +++ b/mmv1/products/workstations/WorkstationConfig.yaml @@ -75,8 +75,6 @@ examples: workstation_config_name: 'workstation-config' tag_key1: 'tag_key1' tag_value1: 'tag_value1' - tag_key2: 'tag_key2' - tag_value2: 'tag_value2' - !ruby/object:Provider::Terraform::Examples name: 'workstation_config_container' min_version: beta diff --git a/mmv1/templates/terraform/examples/workstation_config_basic.tf.erb b/mmv1/templates/terraform/examples/workstation_config_basic.tf.erb index 1925d7b016b6..692461e52dab 100644 --- a/mmv1/templates/terraform/examples/workstation_config_basic.tf.erb +++ b/mmv1/templates/terraform/examples/workstation_config_basic.tf.erb @@ -1,3 +1,21 @@ +resource "google_project" "project" { + project_id = "<%= ctx[:vars]['project_id'] %>" + name = "<%= ctx[:vars]['project_id'] %>" + org_id = "<%= ctx[:test_env_vars]['org_id'] %>" +} + +resource "google_tags_tag_key" "tag_key1" { + provider = "google-beta" + parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>" + short_name = "<%= ctx[:vars]['tag_key1'] %>" +} + +resource "google_tags_tag_value" "tag_value1" { + provider = "google-beta" + parent = "tagKeys/${google_tags_tag_key.tag_key1.name}" + short_name = "<%= ctx[:vars]['tag_value1'] %>" +} + resource "google_compute_network" "default" { provider = google-beta name = "<%= ctx[:vars]['workstation_cluster_name'] %>" @@ -52,6 +70,9 @@ resource "google_workstations_workstation_config" "<%= ctx[:primary_resource_id] boot_disk_size_gb = 35 disable_public_ip_addresses = true disable_ssh = false + vm_tags = { + "tagKeys/${google_tags_tag_key.tag_key1.short_name}" = "tagValues/${google_tags_tag_value.tag_value1.short_name}" + } } } } 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 16fb4c655cdf..7fed741b8039 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 @@ -1293,4 +1293,91 @@ resource "google_workstations_workstation_config" "default" { } `, context) } + +func TestAccWorkstationsWorkstationConfig_vmTags(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_vmTags(context), + }, + { + ResourceName: "google_workstations_workstation_cluster.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag"}, + }, + }, + }) +} + +func testAccWorkstationsWorkstationConfig_vmTags(context map[string]interface{}) string { + return acctest.Nprintf(` + data "google_project" "project" { + provider = "google-beta" + } + + resource "google_tags_tag_key" "tag_key1" { + provider = google-beta + parent = "projects/${data.google_project.project.number}" + short_name = "tf_test_tag_key1%{random_suffix}" + } + + resource "google_tags_tag_value" "tag_value1" { + provider = google-beta + parent = "tagKeys/${google_tags_tag_key.tag_key1.name}" + short_name = "tf_test_tag_value1%{random_suffix}" + } + +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 { + machine_type = "e2-standard-4" + boot_disk_size_gb = 35 + disable_public_ip_addresses = true + vm_tags = { + "tagKeys/${google_tags_tag_key.tag_key1.name}" = "tagValues/${google_tags_tag_value.tag_value1.name}" + } + } + } + +} +`, context) +} + <% end -%> From 3e45788e1e7e848f3bff992395f90790fb6798c2 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Thu, 27 Jun 2024 20:34:58 +0000 Subject: [PATCH 3/3] add the test to the template file --- ...rkstations_workstation_config_test.go.tmpl | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/mmv1/third_party/terraform/services/workstations/go/resource_workstations_workstation_config_test.go.tmpl b/mmv1/third_party/terraform/services/workstations/go/resource_workstations_workstation_config_test.go.tmpl index 576a21ca1262..b3fa64133ba6 100644 --- a/mmv1/third_party/terraform/services/workstations/go/resource_workstations_workstation_config_test.go.tmpl +++ b/mmv1/third_party/terraform/services/workstations/go/resource_workstations_workstation_config_test.go.tmpl @@ -1292,4 +1292,90 @@ resource "google_workstations_workstation_config" "default" { } `, context) } + +func TestAccWorkstationsWorkstationConfig_vmTags(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_vmTags(context), + }, + { + ResourceName: "google_workstations_workstation_cluster.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag"}, + }, + }, + }) +} + +func testAccWorkstationsWorkstationConfig_vmTags(context map[string]interface{}) string { + return acctest.Nprintf(` + data "google_project" "project" { + provider = "google-beta" + } + + resource "google_tags_tag_key" "tag_key1" { + provider = google-beta + parent = "projects/${data.google_project.project.number}" + short_name = "tf_test_tag_key1%{random_suffix}" + } + + resource "google_tags_tag_value" "tag_value1" { + provider = google-beta + parent = "tagKeys/${google_tags_tag_key.tag_key1.name}" + short_name = "tf_test_tag_value1%{random_suffix}" + } + +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 { + machine_type = "e2-standard-4" + boot_disk_size_gb = 35 + disable_public_ip_addresses = true + vm_tags = { + "tagKeys/${google_tags_tag_key.tag_key1.name}" = "tagValues/${google_tags_tag_value.tag_value1.name}" + } + } + } + +} +`, context) +} {{- end }}