From e5654d89ee8e4f91b0fac7362afed67514ce06fb Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 27 Jun 2024 14:19:21 -0700 Subject: [PATCH] feat: added new field vm_tags to the workstation config (#11015) (#7644) [upstream:19fa1816cf373f84daa252027cf7e10855f37b14] Signed-off-by: Modular Magician --- .changelog/11015.txt | 4 + ...tions_workstation_config_generated_test.go | 105 ++++++++++++++++++ ...esource_workstations_workstation_config.go | 37 +++++- ...tions_workstation_config_generated_test.go | 21 ++++ ...ce_workstations_workstation_config_test.go | 86 ++++++++++++++ ...kstations_workstation_config.html.markdown | 29 +++++ 6 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 .changelog/11015.txt diff --git a/.changelog/11015.txt b/.changelog/11015.txt new file mode 100644 index 0000000000..0bbc72bb52 --- /dev/null +++ b/.changelog/11015.txt @@ -0,0 +1,4 @@ +```release-note:REPLACEME + Added new field vm_tags to the workstation config + +``` \ No newline at end of file diff --git a/google-beta/services/workstations/iam_workstations_workstation_config_generated_test.go b/google-beta/services/workstations/iam_workstations_workstation_config_generated_test.go index 93ede11b40..5787d696ad 100644 --- a/google-beta/services/workstations/iam_workstations_workstation_config_generated_test.go +++ b/google-beta/services/workstations/iam_workstations_workstation_config_generated_test.go @@ -125,6 +125,24 @@ func TestAccWorkstationsWorkstationConfigIamPolicyGenerated(t *testing.T) { func testAccWorkstationsWorkstationConfigIamMember_basicGenerated(context map[string]interface{}) string { return acctest.Nprintf(` +resource "google_project" "project" { + project_id = "" + name = "" + org_id = "" +} + +resource "google_tags_tag_key" "tag_key1" { + provider = "google-beta" + parent = "organizations/" + 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}" @@ -179,6 +197,9 @@ resource "google_workstations_workstation_config" "default" { 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}" + } } } } @@ -197,6 +218,24 @@ resource "google_workstations_workstation_config_iam_member" "foo" { func testAccWorkstationsWorkstationConfigIamPolicy_basicGenerated(context map[string]interface{}) string { return acctest.Nprintf(` +resource "google_project" "project" { + project_id = "" + name = "" + org_id = "" +} + +resource "google_tags_tag_key" "tag_key1" { + provider = "google-beta" + parent = "organizations/" + 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}" @@ -251,6 +290,9 @@ resource "google_workstations_workstation_config" "default" { 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}" + } } } } @@ -287,6 +329,24 @@ data "google_workstations_workstation_config_iam_policy" "foo" { func testAccWorkstationsWorkstationConfigIamPolicy_emptyBinding(context map[string]interface{}) string { return acctest.Nprintf(` +resource "google_project" "project" { + project_id = "" + name = "" + org_id = "" +} + +resource "google_tags_tag_key" "tag_key1" { + provider = "google-beta" + parent = "organizations/" + 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}" @@ -341,6 +401,9 @@ resource "google_workstations_workstation_config" "default" { 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}" + } } } } @@ -362,6 +425,24 @@ resource "google_workstations_workstation_config_iam_policy" "foo" { func testAccWorkstationsWorkstationConfigIamBinding_basicGenerated(context map[string]interface{}) string { return acctest.Nprintf(` +resource "google_project" "project" { + project_id = "" + name = "" + org_id = "" +} + +resource "google_tags_tag_key" "tag_key1" { + provider = "google-beta" + parent = "organizations/" + 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}" @@ -416,6 +497,9 @@ resource "google_workstations_workstation_config" "default" { 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}" + } } } } @@ -434,6 +518,24 @@ resource "google_workstations_workstation_config_iam_binding" "foo" { func testAccWorkstationsWorkstationConfigIamBinding_updateGenerated(context map[string]interface{}) string { return acctest.Nprintf(` +resource "google_project" "project" { + project_id = "" + name = "" + org_id = "" +} + +resource "google_tags_tag_key" "tag_key1" { + provider = "google-beta" + parent = "organizations/" + 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}" @@ -488,6 +590,9 @@ resource "google_workstations_workstation_config" "default" { 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/google-beta/services/workstations/resource_workstations_workstation_config.go b/google-beta/services/workstations/resource_workstations_workstation_config.go index ea1967f7a7..a11182d354 100644 --- a/google-beta/services/workstations/resource_workstations_workstation_config.go +++ b/google-beta/services/workstations/resource_workstations_workstation_config.go @@ -425,6 +425,16 @@ See https://cloud.google.com/workstations/docs/reference/rest/v1beta/projects.lo Type: schema.TypeString, }, }, + "vm_tags": { + Type: schema.TypeMap, + Optional: true, + 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'.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, }, }, }, @@ -1032,7 +1042,8 @@ func resourceWorkstationsWorkstationConfigUpdate(d *schema.ResourceData, meta in "host.gceInstance.confidentialInstanceConfig.enableConfidentialCompute", "host.gceInstance.accelerators", "host.gceInstance.boostConfigs", - "host.gceInstance.disableSsh") + "host.gceInstance.disableSsh", + "host.gceInstance.vmTags") } if d.HasChange("persistent_directories") { @@ -1296,6 +1307,8 @@ func flattenWorkstationsWorkstationConfigHostGceInstance(v interface{}, d *schem flattenWorkstationsWorkstationConfigHostGceInstanceAccelerators(original["accelerators"], d, config) transformed["boost_configs"] = flattenWorkstationsWorkstationConfigHostGceInstanceBoostConfigs(original["boostConfigs"], d, config) + transformed["vm_tags"] = + flattenWorkstationsWorkstationConfigHostGceInstanceVmTags(original["vmTags"], d, config) return []interface{}{transformed} } func flattenWorkstationsWorkstationConfigHostGceInstanceMachineType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { @@ -1553,6 +1566,10 @@ func flattenWorkstationsWorkstationConfigHostGceInstanceBoostConfigsAccelerators return v // let terraform core handle it otherwise } +func flattenWorkstationsWorkstationConfigHostGceInstanceVmTags(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenWorkstationsWorkstationConfigPersistentDirectories(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return v @@ -2030,6 +2047,13 @@ func expandWorkstationsWorkstationConfigHostGceInstance(v interface{}, d tpgreso transformed["boostConfigs"] = transformedBoostConfigs } + transformedVmTags, err := expandWorkstationsWorkstationConfigHostGceInstanceVmTags(original["vm_tags"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedVmTags); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["vmTags"] = transformedVmTags + } + return transformed, nil } @@ -2288,6 +2312,17 @@ func expandWorkstationsWorkstationConfigHostGceInstanceBoostConfigsAcceleratorsC return v, nil } +func expandWorkstationsWorkstationConfigHostGceInstanceVmTags(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { + if v == nil { + return map[string]string{}, nil + } + m := make(map[string]string) + for k, val := range v.(map[string]interface{}) { + m[k] = val.(string) + } + return m, nil +} + func expandWorkstationsWorkstationConfigPersistentDirectories(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) req := make([]interface{}, 0, len(l)) diff --git a/google-beta/services/workstations/resource_workstations_workstation_config_generated_test.go b/google-beta/services/workstations/resource_workstations_workstation_config_generated_test.go index f1db61a4e6..3f70f7fe51 100644 --- a/google-beta/services/workstations/resource_workstations_workstation_config_generated_test.go +++ b/google-beta/services/workstations/resource_workstations_workstation_config_generated_test.go @@ -57,6 +57,24 @@ func TestAccWorkstationsWorkstationConfig_workstationConfigBasicExample(t *testi func testAccWorkstationsWorkstationConfig_workstationConfigBasicExample(context map[string]interface{}) string { return acctest.Nprintf(` +resource "google_project" "project" { + project_id = "" + name = "" + org_id = "" +} + +resource "google_tags_tag_key" "tag_key1" { + provider = "google-beta" + parent = "organizations/" + 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}" @@ -111,6 +129,9 @@ resource "google_workstations_workstation_config" "default" { 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/google-beta/services/workstations/resource_workstations_workstation_config_test.go b/google-beta/services/workstations/resource_workstations_workstation_config_test.go index ffb5829849..1cd2e2a037 100644 --- a/google-beta/services/workstations/resource_workstations_workstation_config_test.go +++ b/google-beta/services/workstations/resource_workstations_workstation_config_test.go @@ -1292,3 +1292,89 @@ 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) +} diff --git a/website/docs/r/workstations_workstation_config.html.markdown b/website/docs/r/workstations_workstation_config.html.markdown index 9af0304137..d5283b8902 100644 --- a/website/docs/r/workstations_workstation_config.html.markdown +++ b/website/docs/r/workstations_workstation_config.html.markdown @@ -39,6 +39,24 @@ To get more information about WorkstationConfig, see: ```hcl +resource "google_project" "project" { + project_id = "" + name = "" + org_id = "" +} + +resource "google_tags_tag_key" "tag_key1" { + provider = "google-beta" + parent = "organizations/" + short_name = "tag_key1" +} + +resource "google_tags_tag_value" "tag_value1" { + provider = "google-beta" + parent = "tagKeys/${google_tags_tag_key.tag_key1.name}" + short_name = "tag_value1" +} + resource "google_compute_network" "default" { provider = google-beta name = "workstation-cluster" @@ -93,6 +111,9 @@ resource "google_workstations_workstation_config" "default" { 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}" + } } } } @@ -728,6 +749,14 @@ The following arguments are supported: A list of the boost configurations that workstations created using this workstation configuration are allowed to use. Structure is [documented below](#nested_boost_configs). +* `vm_tags` - + (Optional) + 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`. + The `shielded_instance_config` block supports: