Terraform and Cloud Workstations: Reproducibility at the IaC to Persistent Home Boundary
0 reputation · 28 Jun 2022, 03:54 UTC
0 reputation · 28 Jun 2022, 03:54 UTC
A repeatable development environment is being defined with Cloud Workstations provisioned declaratively via Terraform. The workstation configuration expresses cluster, machine type, and container image, and IAM bindings for workstation users can be codified in the same plan.
The integration boundary is between the Terraform-managed configuration and the developer-facing runtime state. The container image and machine spec are reproducible, while the persistent home directory is designed to retain user state across stops, starts, and image updates. This creates an unresolved decision about where reproducibility should live: in an immutable, versioned custom container image stored in Artifact Registry, or in flexible startup scripts that run on each start. Ephemeral versus persistent home is a configuration choice that trades reproducibility for convenience.
With that boundary in mind:
1. Does disabling persistent home guarantee that a workstation rebuilt by Terraform after destroy yields identical developer state, assuming a pinned custom image?
Yes – when persistent_home_enabled is set to false, the workstation starts from the container image alone. The image must be immutable (e.g., a pinned tag or digest). No runtime modifications can survive a destroy/apply cycle, so the environment is reproducible across rebuilds.
2. When a workstation configuration is updated to a new image tag, what state from the persistent home directory survives and can cause divergence between developers using the same configuration?
$HOME that were written during a session (dotfiles, local caches, SSH keys, installed packages that write to $HOME, etc.) remain untouched..bashrc, .zshrc, IDE settings stored in $HOME) will persist even if the base image changes.3. How do organization policy constraints interact with a Terraform‑defined workstation configuration to affect whether the configuration can actually launch?
compute.requireOsLogin set to TRUE but the workstation uses a non‑OS‑Login account), the terraform apply will fail with a permission‑denied error.compute.machineTypeLocationPolicy) can block creation in a region where the chosen machine type is not allowed.google_cloud_workstation resource.resource "google_cloud_workstation" "dev_ws" {
name = "dev-ws"
location = "us-central1"
machine_type = "n2-standard-4"
persistent_home_enabled = false
image {
image_uri = "us-docker.pkg.dev/my-project/my-repo/my-image:1.0.0"
}
}
terraform init
terraform apply
terraform destroy -auto-approve
terraform apply
# Check that installed packages, dotfiles, etc., match the image contents
resource "google_cloud_workstation" "dev_ws" {
...
persistent_home_enabled = true
}
gcloud resource-manager org-policies list --project=$PROJECT_ID
and compare the output to the workstation settings. If a policy blocks a required feature, adjust the policy or the workstation configuration accordingly.If you encounter an unexpected launch failure after applying the configuration, please confirm whether any organization policy (e.g., compute.requireOsLogin, compute.machineTypeLocationPolicy) is set to TRUE or DENY for the target project. This detail will determine whether the policy is the root cause and whether you need to modify the policy or the workstation definition.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.