Last active
March 23, 2026 22:04
-
-
Save joshuatobin/8701485c7be93c2671f9fdb9a24e6875 to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| # Claude Code Terraform Interview Setup | |
| # Paste and run on remote machine after SSH-ing in | |
| # Create directory structure | |
| mkdir -p .claude/rules .claude/skills/tf-plan | |
| # Create terraform rules file (path-scoped to .tf files only) | |
| cat > .claude/rules/terraform.md << 'RULES' | |
| --- | |
| paths: | |
| - "**/*.tf" | |
| --- | |
| # Terraform Rules | |
| - Always pin provider versions with ~> constraints | |
| - Every variable must have a description and type | |
| - Every resource must have labels/tags: environment, managed_by=terraform | |
| - Use locals for any value referenced more than once | |
| - Never use default VPC -- always custom with auto_create_subnetworks = false | |
| - Database resources must have lifecycle { prevent_destroy = true } | |
| - No hardcoded IPs or CIDRs -- use variables | |
| - No 0.0.0.0/0 ingress unless explicitly required and documented | |
| - Use for_each over count where possible | |
| - Sensitive values use sensitive = true | |
| RULES | |
| # Create custom /tf-plan skill (chains fmt -> validate -> plan) | |
| cat > .claude/skills/tf-plan/SKILL.md << 'SKILL' | |
| --- | |
| name: tf-plan | |
| description: Format, validate, and plan Terraform changes | |
| allowed-tools: Bash(terraform *) | |
| --- | |
| Run the following in order, stop if any step fails: | |
| 1. `terraform fmt -recursive .` | |
| 2. `terraform validate` | |
| 3. `terraform plan -out=tfplan` | |
| 4. Summarize the plan: what will be created, changed, or destroyed | |
| 5. Flag any destructive operations (destroy/replace) with a warning | |
| SKILL | |
| # Create settings with auto-fmt hook on .tf file writes | |
| cat > .claude/settings.json << 'SETTINGS' | |
| { | |
| "hooks": { | |
| "PostToolUse": [ | |
| { | |
| "matcher": "Write|Edit", | |
| "hooks": [ | |
| { | |
| "type": "command", | |
| "command": "file=$(cat | jq -r '.tool_input.file_path // empty'); if [ -n \"$file\" ] && echo \"$file\" | grep -q '\\.tf$'; then terraform fmt \"$file\" 2>/dev/null; fi" | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| } | |
| SETTINGS | |
| echo "Claude Code Terraform setup complete" | |
| echo " - .claude/rules/terraform.md (path-scoped TF rules)" | |
| echo " - .claude/skills/tf-plan/ (custom /tf-plan skill)" | |
| echo " - .claude/settings.json (auto-fmt hook on .tf writes)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment