Skip to content

Commit

Permalink
Cloud Workstations - Workstation (#7018)
Browse files Browse the repository at this point in the history
  • Loading branch information
bschaatsbergen authored Mar 2, 2023
1 parent 16ec6e9 commit 75c90f6
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 2 deletions.
105 changes: 105 additions & 0 deletions mmv1/products/workstations/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,108 @@ objects:
description: |
A list of messages that carry the error details.
item_type: Api::Type::KeyValuePairs
- !ruby/object:Api::Resource
name: "Workstation"
self_link: "projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}/workstationConfigs/{{workstation_config_id}}/workstations/{{workstation_id}}"
base_url: "projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}/workstationConfigs/{{workstation_config_id}}/workstations"
create_url: "projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}/workstationConfigs/{{workstation_config_id}}/workstations?workstationId={{workstation_id}}"
update_verb: :PATCH
update_mask: true
min_version: beta
description: "A single instance of a developer workstation with its own persistent storage."
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
"Workstations": "https://cloud.google.com/workstations/docs/"
api: "https://cloud.google.com/workstations/docs/reference/rest/v1beta/projects.locations.workstationClusters.workstationConfigs.workstations"
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
path: "name"
base_url: "{{op_id}}"
wait_ms: 1000
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 30
update_minutes: 30
delete_minutes: 30
result: !ruby/object:Api::OpAsync::Result
path: "response"
status: !ruby/object:Api::OpAsync::Status
path: "done"
complete: true
allowed:
- true
- false
error: !ruby/object:Api::OpAsync::Error
path: "error"
message: "message"
parameters:
- !ruby/object:Api::Type::String
name: "workstationId"
required: true
input: true
url_param_only: true
description: |
ID to use for the workstation.
- !ruby/object:Api::Type::String
name: "workstationConfigId"
required: true
input: true
url_param_only: true
description: |
The ID of the workstation cluster config.
- !ruby/object:Api::Type::String
name: "workstationClusterId"
required: true
input: true
url_param_only: true
description: |
The name of the workstation cluster.
- !ruby/object:Api::Type::String
name: "location"
input: true
required: true
url_param_only: true
description: |
The location where the workstation cluster config should reside.
properties:
- !ruby/object:Api::Type::String
name: "name"
output: true
description: |
The name of the cluster resource.
- !ruby/object:Api::Type::String
name: "uid"
output: true
description: |
The system-generated UID of the resource.
- !ruby/object:Api::Type::String
name: "displayName"
description: |
Human-readable name for this resource.
- !ruby/object:Api::Type::KeyValuePairs
name: "labels"
description: "Client-specified labels that are applied to the resource and that are also propagated to the underlying Compute Engine resources."
- !ruby/object:Api::Type::KeyValuePairs
name: "annotations"
description: "Client-specified annotations. This is distinct from labels."
- !ruby/object:Api::Type::Time
name: "createTime"
description: |
Time the Instance was created in UTC.
output: true
- !ruby/object:Api::Type::String
name: "host"
description: |
Host to which clients can send HTTPS traffic that will be received by the workstation.
Authorized traffic will be received to the workstation as HTTP on port 80.
To send traffic to a different port, clients may prefix the host with the destination port in the format "{port}-{host}".
output: true
- !ruby/object:Api::Type::Enum
name: "state"
output: true
description: |
Current state of the workstation.
values:
- :STATE_STARTING
- :STATE_RUNNING
- :STATE_STOPPING
- :STATE_STOPPED
17 changes: 15 additions & 2 deletions mmv1/products/workstations/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
import_format:
[
"projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}",
"{{workstation_cluster_id}}",
]
autogen_async: true
examples:
Expand All @@ -38,7 +37,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
import_format:
[
"projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}/workstationConfigs/{{workstation_config_id}}",
"{{workstation_config_id}}",
]
autogen_async: true
properties:
Expand Down Expand Up @@ -110,3 +108,18 @@ overrides: !ruby/object:Overrides::ResourceOverrides
account_id: "my-account"
workstation_cluster_name: "workstation-cluster"
workstation_config_name: "workstation-config"
Workstation: !ruby/object:Overrides::Terraform::ResourceOverride
import_format:
[
"projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}/workstationConfigs/{{workstation_config_id}}/workstations/{{workstation_id}}",
]
autogen_async: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: "workstation_basic"
min_version: beta
primary_resource_id: "default"
vars:
workstation_cluster_name: "workstation-cluster"
workstation_config_name: "workstation-config"
workstation_name: "workstation"
60 changes: 60 additions & 0 deletions mmv1/templates/terraform/examples/workstation_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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
}
}
}

resource "google_workstations_workstation" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
workstation_id = "<%= ctx[:vars]['workstation_name'] %>"
workstation_config_id = google_workstations_workstation_config.<%= ctx[:primary_resource_id] %>.workstation_config_id
workstation_cluster_id = google_workstations_workstation_cluster.<%= ctx[:primary_resource_id] %>.workstation_cluster_id
location = "us-central1"

labels = {
"label" = "key"
}

annotations = {
label-one = "value-one"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<% autogen_exception -%>
package google
<% unless version == "ga" -%>

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccWorkstationsWorkstation_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckWorkstationsWorkstationDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccWorkstationsWorkstation_basic(context),
},
{
ResourceName: "google_workstations_workstation_cluster.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag"},
},
{
Config: testAccWorkstationsWorkstation_modified(context),
},
{
ResourceName: "google_workstations_workstation_cluster.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag"},
},
},
})
}


func testAccWorkstationsWorkstation_basic(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_network" "default" {
name = "tf-test-workstation-cluster%{random_suffix}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "default" {
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" {
workstation_cluster_id = "tf-test-workstation-cluster%{random_suffix}"
network = google_compute_network.default.id
subnetwork = google_compute_subnetwork.default.id
location = "us-central1"

labels = {
foo = "bar"
}
}

resource "google_workstations_workstation_config" "default" {
workstation_config_id = "tf-test-workstation-config%{random_suffix}"
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
location = "us-central1"

labels = {
foo = "bar"
}
}

resource "google_workstations_workstation" "default" {
workstation_id = "tf-test-workstation%{random_suffix}"
workstation_config_id = google_workstations_workstation_config.default.workstation_config_id
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
location = "us-central1"

labels = {
foo = "bar"
}
}
`, context)
}

func testAccWorkstationsWorkstation_modified(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_network" "default" {
name = "tf-test-workstation-cluster%{random_suffix}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "default" {
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" {
workstation_cluster_id = "tf-test-workstation-cluster%{random_suffix}"
network = google_compute_network.default.id
subnetwork = google_compute_subnetwork.default.id
location = "us-central1"

labels = {
foo = "bar"
}
}

resource "google_workstations_workstation_config" "default" {
workstation_config_id = "tf-test-workstation-config%{random_suffix}"
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
location = "us-central1"

labels = {
foo = "bar"
}
}

resource "google_workstations_workstation" "default" {
workstation_id = "tf-test-workstation%{random_suffix}"
workstation_config_id = google_workstations_workstation_config.default.workstation_config_id
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id
location = "us-central1"
display_name = "workstation%{random_suffix}"

labels = {
foo = "bar"
}
}
`, context)
}
<% end -%>

0 comments on commit 75c90f6

Please sign in to comment.