Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added new field vm_tags to the workstation config #11015

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tejal29 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the new test isn't added as part of magic-modules/mmv1/third_party/terraform/services/workstations/go/resource_workstations_workstation_config_test.go.tmpl

could you add this? this may be the reason for the unusual errors. I don't see anything that stands out that would cause the rest of the tests to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. Will do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got confirmation that the failing tests are unrelated. We can approve and merge this with the new info 🎊

<% end -%>