Skip to content

Commit f1c7c9f

Browse files
feat: update vertex examples with tested working examples
1 parent 8b13760 commit f1c7c9f

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

registry/coder/modules/claude-code/README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,17 @@ module "claude-code" {
195195

196196
#### Prerequisites
197197

198-
GCP project with Vertex AI API enabled, Claude models enabled through Model Garden, Google Cloud authentication configured, appropriate IAM permissions.
198+
GCP project with Vertex AI API enabled, Claude models enabled through Model Garden, service account with Vertex AI permissions, appropriate IAM permissions (Vertex AI User role).
199199

200200
Configure Claude Code to use Google Vertex AI for accessing Claude models through Google Cloud Platform.
201201

202202
```tf
203+
variable "vertex_sa_json" {
204+
type = string
205+
description = "The complete JSON content of your Google Cloud service account key file. Create a service account in the GCP Console under 'IAM & Admin > Service Accounts', then create and download a JSON key. Copy the entire JSON content into this variable."
206+
sensitive = true
207+
}
208+
203209
resource "coder_env" "vertex_use" {
204210
agent_id = coder_agent.example.id
205211
name = "CLAUDE_CODE_USE_VERTEX"
@@ -218,12 +224,46 @@ resource "coder_env" "cloud_ml_region" {
218224
value = "global"
219225
}
220226
227+
resource "coder_env" "vertex_sa_json" {
228+
agent_id = coder_agent.example.id
229+
name = "VERTEX_SA_JSON"
230+
value = var.vertex_sa_json
231+
}
232+
233+
resource "coder_env" "google_application_credentials" {
234+
agent_id = coder_agent.example.id
235+
name = "GOOGLE_APPLICATION_CREDENTIALS"
236+
value = "/tmp/gcp-sa.json"
237+
}
238+
221239
module "claude-code" {
222240
source = "registry.coder.com/coder/claude-code/coder"
223241
version = "3.1.1"
224242
agent_id = coder_agent.example.id
225243
workdir = "/home/coder/project"
226244
model = "claude-sonnet-4@20250514"
245+
246+
pre_install_script = <<-EOT
247+
#!/bin/bash
248+
# Write the service account JSON to a file
249+
echo "$VERTEX_SA_JSON" > /tmp/gcp-sa.json
250+
251+
# Install prerequisite packages
252+
sudo apt-get update
253+
sudo apt-get install -y apt-transport-https ca-certificates gnupg curl
254+
255+
# Add Google Cloud public key
256+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
257+
258+
# Add Google Cloud SDK repo to apt sources
259+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list
260+
261+
# Update and install the Google Cloud SDK
262+
sudo apt-get update && sudo apt-get install -y google-cloud-cli
263+
264+
# Authenticate gcloud with the service account
265+
gcloud auth activate-service-account --key-file=/tmp/gcp-sa.json
266+
EOT
227267
}
228268
```
229269

0 commit comments

Comments
 (0)