Skip to content

Commit

Permalink
feat: added new field vm_tags to the workstation config (GoogleCloudP…
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 authored and vijaykanthm committed Jul 22, 2024
1 parent 179bd37 commit 8162902
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mmv1/products/workstations/WorkstationConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ examples:
vars:
workstation_cluster_name: 'workstation-cluster'
workstation_config_name: 'workstation-config'
tag_key1: 'tag_key1'
tag_value1: 'tag_value1'
- !ruby/object:Provider::Terraform::Examples
name: 'workstation_config_container'
min_version: beta
Expand Down Expand Up @@ -222,6 +224,7 @@ properties:
- 'host.gceInstance.accelerators'
- 'host.gceInstance.boostConfigs'
- 'host.gceInstance.disableSsh'
- 'host.gceInstance.vmTags'
properties:
- !ruby/object:Api::Type::NestedObject
name: 'gceInstance'
Expand Down Expand Up @@ -376,6 +379,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: |
Expand Down
21 changes: 21 additions & 0 deletions mmv1/templates/terraform/examples/workstation_config_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -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'] %>"
Expand Down Expand Up @@ -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}"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>

0 comments on commit 8162902

Please sign in to comment.