Created
July 25, 2023 04:18
-
-
Save ConnorD/239e2f9d8527d5de2c05af3301328350 to your computer and use it in GitHub Desktop.
Manage Google Cloud Workstation Configuration with Accelerators (GPU)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
project_id = "[PROJECT ID]" | |
default_region = "[REGION]" | |
workstation_cluster_id = google_workstations_workstation_cluster.default.workstation_cluster_id | |
workstation_config_id = google_workstations_workstation_config.default.workstation_config_id | |
image_url = "[IMAGE URL]" | |
machine_type = "n1-standard-8" | |
instance_pool_size = 1 | |
accelerators = <<EOF | |
[{"type":"nvidia-tesla-t4","count":1}] | |
EOF | |
} | |
resource "shell_script" "workstation_config_amp_axon" { | |
# using the `shell_script` resource type is sub-optimal here, but the GCP Terraform provider does not yet support the "accelerators" setting for Cloud Workstations. | |
lifecycle_commands { | |
create = <<EOF | |
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -d '{"persistent_directories": {"mount_path": "/home", "gce_pd": {"size_gb": 500, "reclaim_policy": "DELETE"}}, "container": {"image": "${local.image_url}"}, "host": {"gceInstance": {"machineType":"${local.machine_type}", "poolSize": ${local.instance_pool_size}, "accelerators":${local.accelerators}}}}' https://workstations.googleapis.com/v1alpha/projects/${local.project_id}/locations/${local.default_region}/workstationClusters/${local.workstation_cluster_id}/workstationConfigs?workstation_config_id=${local.workstation_config_id} | |
EOF | |
read = <<EOF | |
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" https://workstations.googleapis.com/v1alpha/projects/${local.project_id}/locations/${local.default_region}/workstationClusters/${local.workstation_cluster_id}/workstationConfigs/${local.workstation_config_id} | |
EOF | |
delete = <<EOF | |
curl -X DELETE -H "Authorization: Bearer $(gcloud auth print-access-token)" https://workstations.googleapis.com/v1alpha/projects/${local.project_id}/locations/${local.default_region}/workstationClusters/${local.workstation_cluster_id}/workstationConfigs/${local.workstation_config_id} | |
EOF | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment