Skip to content

Commit

Permalink
Add support for boost configs in workstations configs (GoogleCloudPla…
Browse files Browse the repository at this point in the history
…tform#10176)

* add boostConfig workstationConfig

* add boostConfig workstationConfig

* link example

* remove

* update descriptions and add update test

* update machine type

* fix update test
  • Loading branch information
joelkattapuram authored and hao-nan-li committed Apr 9, 2024
1 parent 0bcd366 commit 0148da3
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
39 changes: 39 additions & 0 deletions mmv1/products/workstations/WorkstationConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ examples:
vars:
workstation_cluster_name: 'workstation-cluster'
workstation_config_name: 'workstation-config'
- !ruby/object:Provider::Terraform::Examples
name: 'workstation_config_boost'
min_version: beta
primary_resource_id: 'default'
vars:
workstation_cluster_name: 'workstation-cluster'
workstation_config_name: 'workstation-config'
- !ruby/object:Provider::Terraform::Examples
name: 'workstation_config_encryption_key'
min_version: beta
Expand Down Expand Up @@ -213,6 +220,7 @@ properties:
- 'host.gceInstance.shieldedInstanceConfig.enableIntegrityMonitoring'
- 'host.gceInstance.confidentialInstanceConfig.enableConfidentialCompute'
- 'host.gceInstance.accelerators'
- 'host.gceInstance.boostConfigs'
- 'host.gceInstance.disableSsh'
properties:
- !ruby/object:Api::Type::NestedObject
Expand Down Expand Up @@ -319,6 +327,37 @@ properties:
description: |
Number of accelerator cards exposed to the instance.
required: true
- !ruby/object:Api::Type::Array
name: 'boostConfigs'
description: |
A list of the boost configurations that workstations created using this workstation configuration are allowed to use.
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'id'
description: |
The id to be used for the boost config.
required: true
- !ruby/object:Api::Type::String
name: 'machineType'
description: |
The type of machine that boosted VM instances will use—for example, e2-standard-4. For more information about machine types that Cloud Workstations supports, see the list of available machine types https://cloud.google.com/workstations/docs/available-machine-types. Defaults to e2-standard-4.
- !ruby/object:Api::Type::Array
name: 'accelerators'
description: |
An accelerator card attached to the boost instance.
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'type'
description: |
Type of accelerator resource to attach to the instance, for example, "nvidia-tesla-p100".
required: true
- !ruby/object:Api::Type::Integer
name: 'count'
description: |
Number of accelerator cards exposed to the instance.
required: true
- !ruby/object:Api::Type::Array
name: 'persistentDirectories'
description: |
Expand Down
56 changes: 56 additions & 0 deletions mmv1/templates/terraform/examples/workstation_config_boost.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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
boost_configs {
id = "boost-1"
machine_type = "n1-standard-2"
accelerators {
type = "nvidia-tesla-t4"
count = "1"
}
}
boost_configs {
id = "boost-1"
machine_type = "e2-standard-2"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,80 @@ func testAccWorkstationsWorkstationConfig_serviceAccount(context map[string]inte
`, context)
}

func TestAccWorkstationsWorkstationConfig_boost(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_boost(context),
},
{
ResourceName: "google_workstations_workstation_cluster.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag"},
},
},
})
}

func testAccWorkstationsWorkstationConfig_boost(context map[string]interface{}) string {
return acctest.Nprintf(`
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 {
boost_configs {
id = "boost-1"
machine_type = "n1-standard-2"
accelerators {
type = "nvidia-tesla-t4"
count = 1
}
}
boost_configs {
id = "boost-1"
machine_type = "e2-standard-2"
}
}
}
}
`, context)
}

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

Expand Down Expand Up @@ -886,6 +960,11 @@ resource "google_workstations_workstation_config" "default" {
confidential_instance_config {
enable_confidential_compute = true
}

boost_configs {
id = "boost-1"
machine_type = "n2d-standard-2"
}
}
}
}
Expand Down

0 comments on commit 0148da3

Please sign in to comment.