Skip to content

Commit

Permalink
Cloud Workstations - Workstation Cluster (GoogleCloudPlatform#7005)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Suarez <ScottMSuarez@gmail.com>
Closes hashicorp/terraform-provider-google#12763
  • Loading branch information
bschaatsbergen authored and kubalaguna committed Feb 27, 2023
1 parent b2d68d4 commit ff29549
Show file tree
Hide file tree
Showing 5 changed files with 354 additions and 0 deletions.
174 changes: 174 additions & 0 deletions mmv1/products/workstations/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Copyright 2022 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
!ruby/object:Api::Product
name: Workstations
display_name: Workstations
versions:
- !ruby/object:Api::Product::Version
name: beta
base_url: https://workstations.googleapis.com/v1beta/
scopes:
- https://www.googleapis.com/auth/cloud-platform
apis_required:
- !ruby/object:Api::Product::ApiReference
name: Workstations API
url: https://console.cloud.google.com/apis/library/workstations.googleapis.com
objects:
- !ruby/object:Api::Resource
name: "WorkstationCluster"
self_link: "projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}"
base_url: "projects/{{project}}/locations/{{location}}/workstationClusters"
create_url: "projects/{{project}}/locations/{{location}}/workstationClusters?workstationClusterId={{workstation_cluster_id}}"
update_verb: :PATCH
update_mask: true
min_version: beta
description: "A managed workstation cluster."
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/create"
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: 60
update_minutes: 60
delete_minutes: 60
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: "workstationClusterId"
required: true
input: true
url_param_only: true
description: |
The ID of the workstation cluster.
- !ruby/object:Api::Type::String
name: "location"
input: true
url_param_only: true
description: |
The location where the workstation cluster 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::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::String
name: "network"
required: true
input: true
description: |
The relative resource name of the VPC network on which the instance can be accessed.
It is specified in the following form: "projects/{projectNumber}/global/networks/{network_id}".
- !ruby/object:Api::Type::String
name: "subnetwork"
required: true
input: true
description: |
Name of the Compute Engine subnetwork in which instances associated with this cluster will be created.
Must be part of the subnetwork specified for this cluster.
- !ruby/object:Api::Type::String
name: "displayName"
description: |
Human-readable name for this resource.
- !ruby/object:Api::Type::Boolean
name: "degraded"
description: |
Whether this resource is in degraded mode, in which case it may require user action to restore full functionality.
Details can be found in the conditions field.
output: true
- !ruby/object:Api::Type::KeyValuePairs
name: "annotations"
description: "Client-specified annotations. This is distinct from labels."
- !ruby/object:Api::Type::Fingerprint
name: "etag"
description: |
Checksum computed by the server.
May be sent on update and delete requests to ensure that the client has an up-to-date value before proceeding.
- !ruby/object:Api::Type::Time
name: "createTime"
description: |
Time the Instance was created in UTC.
output: true
- !ruby/object:Api::Type::NestedObject
name: 'privateClusterConfig'
description: |
Configuration for private cluster.
properties:
- !ruby/object:Api::Type::Boolean
name: "enablePrivateEndpoint"
input: true
required: true
description: |
Whether Workstations endpoint is private.
- !ruby/object:Api::Type::String
name: "clusterHostname"
description: |
Hostname for the workstation cluster.
This field will be populated only when private endpoint is enabled.
To access workstations in the cluster, create a new DNS zone mapping this domain name to an internal IP address and a forwarding rule mapping that address to the service attachment.
output: true
- !ruby/object:Api::Type::String
name: "serviceAttachmentUri"
description: |
Service attachment URI for the workstation cluster.
The service attachemnt is created when private endpoint is enabled.
To access workstations in the cluster, configure access to the managed service using (Private Service Connect)[https://cloud.google.com/vpc/docs/configure-private-service-connect-services].
output: true
- !ruby/object:Api::Type::Array
name: "conditions"
description: |-
Status conditions describing the current resource state.
output: true
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::Integer
name: "code"
output: true
description: |-
The status code, which should be an enum value of google.rpc.Code.
- !ruby/object:Api::Type::String
name: "message"
output: true
description: |-
Human readable message indicating details about the current status.
- !ruby/object:Api::Type::Array
name: 'details'
description: |
A list of messages that carry the error details.
item_type: Api::Type::KeyValuePairs
output: true
32 changes: 32 additions & 0 deletions mmv1/products/workstations/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2022 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
!ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
WorkstationCluster: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ["projects/{{project}}/locations/{{location}}/workstationClusters/{{workstation_cluster_id}}", "{{workstation_cluster_id}}"]
autogen_async: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: "workstation_cluster_basic"
min_version: beta
primary_resource_id: "default"
vars:
workstation_cluster_name: "workstation-cluster"
- !ruby/object:Provider::Terraform::Examples
name: "workstation_cluster_private"
min_version: beta
primary_resource_id: "default"
vars:
workstation_cluster_name: "workstation-cluster-private"
33 changes: 33 additions & 0 deletions mmv1/templates/terraform/examples/workstation_cluster_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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"
}
}

data "google_project" "project" {
provider = google-beta
}

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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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"

private_cluster_config {
enable_private_endpoint = true
}

labels = {
"label" = "key"
}

annotations = {
label-one = "value-one"
}
}

data "google_project" "project" {
provider = google-beta
}

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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>

import (
"testing"

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

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

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

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

func testAccorkstationsWorkstationCluster_update(context map[string]interface{}) string {
return Nprintf(`
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"

labels = {
update = "true"
}
}

resource "google_compute_network" "default" {
provider = google-beta
name = "tf-test-workstation-cluster%{random_suffix}"
auto_create_subnetworks = false
}

data "google_project" "project" {
provider = google-beta
}

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
}
`, context)
}
<% end -%>

0 comments on commit ff29549

Please sign in to comment.