diff --git a/examples/templates/gcp-linux/main.tf b/examples/templates/gcp-linux/main.tf index a53a29127bf2c..d97bdae3126a5 100644 --- a/examples/templates/gcp-linux/main.tf +++ b/examples/templates/gcp-linux/main.tf @@ -70,5 +70,21 @@ resource "google_compute_instance" "dev" { email = data.google_compute_default_service_account.default.email scopes = ["cloud-platform"] } - metadata_startup_script = coder_agent.dev.init_script + # The startup script runs as root with no $HOME environment set up, which can break workspace applications, so + # instead of directly running the agent init script, setup the home directory, write the init script, and then execute + # it. + metadata_startup_script = < /root/coder_agent.sh +${coder_agent.dev.init_script} +EOCODER +chmod +x /root/coder_agent.sh + +export HOME=/root +/root/coder_agent.sh + +EOMETA }