claude-skill-hcp-terraform / terraform-mcp-as-code
CLAUDE.md4 starsChanged 13 months agoMITView on GitHub
This is a Claude Code skill for programmatic HCP Terraform automation - a specialized knowledge base that provides comprehensive documentation and TypeScript wrapper functions for automating Terraform Cloud and Terraform Enterprise operations via the HashiCorp Terraform MCP server. Purpose: Enable Claude to help users automate HCP Terraform operations: creating workspaces, triggering runs, managing variables, searching registries (public and private), and orchestrating infrastructure-as-code workflows programmatically. Unlike the other skills in this marketplace (terraform-style-guide, terraform-test, terraform-stacks), this skill includes executable code alongside…
- Reads credentials
In this repository8 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- terraform-stacks/CLAUDE.mdCLAUDE.md
- terraform-style-guide/CLAUDE.mdCLAUDE.md
- terraform-test/CLAUDE.mdCLAUDE.md
- Terraform Infrastructure as CodeSkill
- terraform-stacksSkill
- terraform-style-guideSkill
- terraform-testSkill
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
41 rules. About 0 are common, 35 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈35
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 101
Review generated code: before execution in production environments
- Distinctive: line 128
Purpose: Create, configure, update, and manage Terraform Cloud/Enterprise workspaces
- Very specific: line 190
Security Note: Always set sensitive: "true" for credentials, API keys, and secrets.
- Distinctive: line 194
Purpose: Search and access public Terraform Registry content
- Distinctive: line 197
Search: modules, providers, policies
- Distinctive: line 217
Search: private modules, private providers
- Distinctive: line 299
Create workspace with appropriate settings
- Distinctive: line 306
Use descriptive workspace names
- Distinctive: line 314
Search public registry for modules
- Distinctive: line 320
Search with specific keywords (e.g., "vpc aws terraform-aws-modules")
- Distinctive: line 321
Check module version and compatibility
- Distinctive: line 335
Use meaningful run messages
- Distinctive: line 344
Create variable set with common configuration
- Distinctive: line 346
Update variables in variable set (propagates to all workspaces)
- Distinctive: line 349
Use variable sets for shared configuration
- Distinctive: line 351
Test changes in non-production first
- Distinctive: line 402
Search registries for modules/providers
- Distinctive: line 407
Do NOT use this skill for:
- Distinctive: line 418
terraform-style-guide: Use for writing Terraform configurations, then use this skill to deploy them
- Distinctive: line 419
terraform-test: Use for writing tests, then use this skill to trigger test runs in Cloud/Enterprise
- Distinctive: line 420
terraform-stacks: Use for Stacks configurations, then use this skill to manage Stack deployments programmatically
- Distinctive: line 439
Use the Terraform Cloud/Enterprise API directly (without MCP)
- Distinctive: line 440
Write their own API clients
- Very specific: line 446
Always set sensitive: "true" (string) when creating variables with secrets:
- Distinctive: line 468
Use variable sets for configuration shared across workspaces.
- Distinctive: line 484
Consider implementing retry logic with backoff
- Very specific: line 492
Ensure your TFE_TOKEN matches your target environment.
- Distinctive: line 498
Before using this skill, verify:
- Distinctive: line 507
Check Docker is running
- Distinctive: line 508
Verify MCP server starts correctly
- Very specific: line 512
Verify TFE_TOKEN is set and valid
- Distinctive: line 513
Check token has required permissions
- Distinctive: line 514
Ensure token matches Terraform Cloud/Enterprise instance
- Distinctive: line 517
Use correct Input interface for each function
- Very specific: line 518
Check string vs boolean types (e.g., auto_apply: "true" not true)
- Distinctive: line 519
Verify all required parameters are provided
- Distinctive: line 530
When updating this skill:
- Distinctive: line 532
Keep wrapper functions in sync: - If MCP server API changes, regenerate wrappers
- Very specific: line 533
Update documentation: - Ensure SKILL.md reflects current capabilities
- Distinctive: line 534
Test all examples: - Verify code examples work with current MCP server
- Distinctive: line 535
Maintain security guidelines: - Never include actual tokens in examples
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Skill Overview
This is a Claude Code skill for programmatic HCP Terraform automation - a specialized knowledge base that provides comprehensive documentation and TypeScript wrapper functions for automating Terraform Cloud and Terraform Enterprise operations via the HashiCorp Terraform MCP server.
Purpose: Enable Claude to help users automate HCP Terraform operations: creating workspaces, triggering runs, managing variables, searching registries (public and private), and orchestrating infrastructure-as-code workflows programmatically.
Critical Distinction from Other Skills
Unlike the other skills in this marketplace (terraform-style-guide, terraform-test, terraform-stacks), this skill includes executable code alongside documentation:
- Documentation: SKILL.md provides comprehensive guides and examples
- Executable Code:
scripts/directory contains 34 type-safe TypeScript wrapper functions - Runtime Dependency: Requires Docker and the HashiCorp MCP server to execute
Important: Users must set up the MCP server separately. This skill provides the knowledge and wrapper code, not a running MCP server instance.
Repository Structure
terraform-mcp-as-code/
├── plugin.json # Skill metadata
├── SKILL.md # Main comprehensive guide
├── CLAUDE.md # This file - Claude-specific guidance
├── README.md # User-facing documentation
└── scripts/ # TypeScript wrapper functions (34 tools)
├── client.ts # MCP connection manager
├── organization/ # 2 tools: List orgs/projects
│ ├── index.ts
│ ├── listTerraformOrgs.ts
│ └── listTerraformProjects.ts
├── workspaces/ # 7 tools: Workspace management
│ ├── index.ts
│ ├── createWorkspace.ts
│ ├── updateWorkspace.ts
│ ├── listWorkspaces.ts
│ ├── getWorkspaceDetails.ts
│ ├── createWorkspaceTags.ts
│ ├── readWorkspaceTags.ts
│ └── createNoCodeWorkspace.ts
├── runs/ # 3 tools: Run management
│ ├── index.ts
│ ├── createRun.ts
│ ├── getRunDetails.ts
│ └── listRuns.ts
├── variables/ # 9 tools: Variable management
│ ├── index.ts
│ ├── createWorkspaceVariable.ts
│ ├── updateWorkspaceVariable.ts
│ ├── deleteWorkspaceVariable.ts
│ ├── createVariableSet.ts
│ ├── updateVariableSet.ts
│ ├── createVariableInVariableSet.ts
│ ├── updateVariableInVariableSet.ts
│ ├── deleteVariableInVariableSet.ts
│ └── attachVariableSetToWorkspaces.ts
├── public-registry/ # 9 tools: Public registry access
│ ├── index.ts
│ ├── searchModules.ts
│ ├── searchProviders.ts
│ ├── searchPolicies.ts
│ ├── getModuleDetails.ts
│ ├── getProviderDetails.ts
│ ├── getPolicyDetails.ts
│ ├── getModuleReadme.ts
│ ├── getProviderDocs.ts
│ └── getProviderCapabilities.ts
└── private-registry/ # 4 tools: Private registry access
├── index.ts
├── searchPrivateModules.ts
├── searchPrivateProviders.ts
├── getPrivateModuleDetails.ts
└── getPrivateProviderDetails.tsPrerequisites and Environment Setup
Required Environment
For execution, users need:
- Terraform Cloud/Enterprise account with valid API token
- Docker installed and running
TFE_TOKENenvironment variable set with a valid Terraform API token- Node.js (if running TypeScript wrappers locally, though this is optional for Claude Code usage)
MCP Server Command:
docker run -i --rm -e TFE_TOKEN=your_token hashicorp/terraform-mcp-serverSecurity Considerations
Critical Security Guidelines:
- NEVER hardcode
TFE_TOKENin code - always use environment variables - NEVER commit tokens to version control
- Use least-privilege tokens - workspace-specific or org-specific when possible
- Review generated code before execution in production environments
- Store tokens securely in credential managers or environment configuration
Example secure vs insecure code:
// ✅ Correct: Use environment variables
const token = process.env.TFE_TOKEN;
// ❌ Wrong: Hardcoded token
const token = "abc123..."; // NEVER DO THISTool Categories and Capabilities
1. Organization Tools (2 tools)
Purpose: Discover available Terraform organizations and projects
Tools:
listTerraformOrgs: List all organizations the token has access tolistTerraformProjects: List projects within a specific organization
Common Use Case: "Which organizations do I have access to?" or "What projects exist in my org?"
2. Workspace Tools (7 tools)
Purpose: Create, configure, update, and manage Terraform Cloud/Enterprise workspaces
Tools:
createWorkspace: Create new workspace with configurationupdateWorkspace: Modify workspace settingslistWorkspaces: List workspaces in an organizationgetWorkspaceDetails: Get detailed workspace informationcreateWorkspaceTags: Add tags to workspacereadWorkspaceTags: Get workspace tagscreateNoCodeWorkspace: Create no-code module workspace
Common Use Cases:
- Setting up new environments (dev, staging, production)
- Configuring workspace settings (auto-apply, Terraform version)
- Organizing workspaces with tags
Critical Parameters:
workspace_name: Unique workspace identifierterraform_org_name: Organization nameauto_apply: "true" or "false" (string, not boolean)execution_mode: "remote", "local", or "agent"
3. Runs Tools (3 tools)
Purpose: Trigger and monitor Terraform runs programmatically
Tools:
createRun: Trigger a new Terraform rungetRunDetails: Get run status and outputlistRuns: List runs with filtering
Common Use Cases:
- Triggering deployments after code changes
- Monitoring run status and output
- Implementing CI/CD pipelines with Terraform
Critical Parameters:
run_type: "plan-and-apply", "plan-only", "refresh-only", or "destroy"message: Description of why the run was triggeredauto_apply: Whether to auto-apply after successful plan
4. Variables Tools (9 tools)
Purpose: Manage workspace variables and variable sets
Tools:
- Workspace Variables: create, update, delete
- Variable Sets: create, update, attach to workspaces
- Variable Set Variables: create, update, delete in variable sets
Common Use Cases:
- Setting environment-specific configuration
- Managing secrets and credentials
- Sharing common variables across workspaces
Critical Parameters:
key: Variable namevalue: Variable valuecategory: "terraform" (TF_VAR_*) or "env" (environment variable)sensitive: "true" to mark as sensitive (string, not boolean)hcl: "true" if value is HCL expression (string, not boolean)
Security Note: Always set sensitive: "true" for credentials, API keys, and secrets.
5. Public Registry Tools (9 tools)
Purpose: Search and access public Terraform Registry content
Tools:
- Search: modules, providers, policies
- Details: module, provider, policy details
- Documentation: module README, provider docs, provider capabilities
Common Use Cases:
- Finding the right module for infrastructure needs
- Researching provider capabilities
- Reading module documentation before usage
Critical Parameters:
module_query,provider_query,policy_query: Search termsmodule_id,provider_id,policy_id: Full identifiers (e.g., "terraform-aws-modules/vpc/aws/5.1.2")
Module ID Format: <namespace>/<name>/<provider>/<version> (e.g., "terraform-aws-modules/vpc/aws/5.1.2")
6. Private Registry Tools (4 tools)
Purpose: Access private Terraform modules and providers in your organization
Tools:
- Search: private modules, private providers
- Details: private module details, private provider details
Common Use Cases:
- Finding internal organization modules
- Discovering custom providers
- Accessing proprietary infrastructure components
Critical Parameters:
terraform_org_name: Organization name for private registry accessmodule_query,provider_query: Search terms
TypeScript Wrapper Architecture
Client Architecture
scripts/client.ts provides the MCP connection manager:
// Initialize MCP connection
await initializeMCPClient({
command: "docker",
args: ["run", "-i", "--rm", "-e", `TFE_TOKEN=${process.env.TFE_TOKEN}`, "hashicorp/terraform-mcp-server"]
});
// Call MCP tools
const result = await callMCPTool("toolName", { param: "value" });
// Clean up connection
await closeMCPClient();Tool Wrapper Pattern
Each tool wrapper follows this pattern:
// Input/Output interfaces from JSON Schema
export interface CreateWorkspaceInput {
workspace_name: string;
terraform_org_name: string;
auto_apply?: string;
description?: string;
// ...
}
export interface CreateWorkspaceOutput {
content: Array<{ type: string; text: string }>;
isError?: boolean;
}
// Type-safe wrapper function
export async function CreateWorkspace(input: CreateWorkspaceInput): Promise<CreateWorkspaceOutput> {
return callMCPTool("CreateWorkspace", input);
}Benefits:
- Full TypeScript type safety
- IDE autocomplete and IntelliSense
- Runtime type validation
- Clear input/output contracts
Barrel Exports
Each category has an index.ts that re-exports all tools:
// Import from category
import { CreateWorkspace, UpdateWorkspace, ListWorkspaces } from "./scripts/workspaces/index.js";
// Or import specific tool with types
import { CreateWorkspace, CreateWorkspaceInput, CreateWorkspaceOutput } from "./scripts/workspaces/createWorkspace.js";Common User Workflows
Workflow 1: Setup New Environment
User Intent: "Create a new production environment for my API service"
Guide to:
- Create workspace with appropriate settings
- Set up variable sets for environment-specific config
- Attach variable sets to workspace
- Trigger initial plan
Key Considerations:
- Set
auto_apply: "false"for production (manual approval) - Use descriptive workspace names
- Tag workspaces for organization
Workflow 2: Find and Use Registry Module
User Intent: "Find a good VPC module for AWS"
Guide to:
- Search public registry for modules
- Get module details and documentation
- Review README and examples
- Reference module in Terraform configuration
Key Considerations:
- Search with specific keywords (e.g., "vpc aws terraform-aws-modules")
- Check module version and compatibility
- Review provider requirements
Workflow 3: Automate Deployments
User Intent: "Trigger deployments automatically when code changes"
Guide to:
- Create runs programmatically
- Monitor run status
- Handle errors and failures
- Implement retry logic if needed
Key Considerations:
- Use meaningful run messages
- Set appropriate run types (plan-and-apply vs plan-only)
- Monitor run status before proceeding
Workflow 4: Manage Configuration at Scale
User Intent: "Update AWS region across 20 workspaces"
Guide to:
- Create variable set with common configuration
- Attach variable set to multiple workspaces
- Update variables in variable set (propagates to all workspaces)
Key Considerations:
- Use variable sets for shared configuration
- Mark sensitive variables appropriately
- Test changes in non-production first
Error Handling Patterns
Standard Error Handling
try {
const result = await CreateWorkspace({
workspace_name: "my-workspace",
terraform_org_name: "my-org"
});
if (result.isError) {
console.error("Workspace creation failed:", result.content);
// Handle error
} else {
console.log("Workspace created successfully");
// Continue workflow
}
} catch (error) {
console.error("MCP call failed:", error);
// Handle connection/system error
}Common Error Scenarios
Connection Errors:
- Docker not running
- MCP server failed to start
- Network issues
Authentication Errors:
- Invalid or expired
TFE_TOKEN - Insufficient permissions for operation
- Token not set in environment
API Errors:
- Workspace already exists
- Organization not found
- Invalid parameter values
Integration with Claude Code
When to Use This Skill
Invoke this skill when users need to:
- Automate Terraform Cloud/Enterprise operations
- Programmatically manage workspaces
- Trigger runs from scripts or CI/CD
- Search registries for modules/providers
- Manage variables at scale
When NOT to Use This Skill
Do NOT use this skill for:
- Direct Terraform CLI operations (use Terraform CLI directly)
- Local Terraform state management (this is Cloud/Enterprise only)
- Writing Terraform configurations (use terraform-style-guide instead)
- Writing Terraform tests (use terraform-test instead)
- Terraform Stacks configurations (use terraform-stacks instead)
Skill Interaction with Other Skills
This skill complements other skills in the marketplace:
- terraform-style-guide: Use for writing Terraform configurations, then use this skill to deploy them
- terraform-test: Use for writing tests, then use this skill to trigger test runs in Cloud/Enterprise
- terraform-stacks: Use for Stacks configurations, then use this skill to manage Stack deployments programmatically
Common User Questions
"How do I authenticate?"
Set the TFE_TOKEN environment variable with a valid Terraform Cloud/Enterprise API token:
export TFE_TOKEN="your-token-here"Get tokens from:
- Terraform Cloud: User Settings → Tokens
- Terraform Enterprise: User Settings → Tokens
"Can I use this without Docker?"
The MCP server requires Docker. However, users could theoretically:
- Use the Terraform Cloud/Enterprise API directly (without MCP)
- Write their own API clients
But this skill is specifically designed for the HashiCorp MCP server approach.
"How do I handle sensitive variables?"
Always set sensitive: "true" (string) when creating variables with secrets:
await CreateWorkspaceVariable({
workspace_name: "my-workspace",
terraform_org_name: "my-org",
key: "AWS_SECRET_ACCESS_KEY",
value: process.env.AWS_SECRET,
category: "env",
sensitive: "true" // String, not boolean!
});"Can I automate Terraform Enterprise on-premises?"
Yes! The MCP server supports both Terraform Cloud (SaaS) and Terraform Enterprise (on-premises). Use the same approach with your organization's Terraform Enterprise URL and API token.
"What's the difference between workspace variables and variable sets?"
- Workspace Variables: Specific to one workspace
- Variable Sets: Shared across multiple workspaces (e.g., AWS credentials for all production workspaces)
Use variable sets for configuration shared across workspaces.
Limitations and Constraints
Not Suitable For
- Direct Terraform CLI operations (plan, apply, destroy locally)
- Local Terraform state management
- Terraform configuration generation (use language skills)
- Non-Terraform infrastructure management
API Rate Limits
Terraform Cloud/Enterprise has API rate limits:
- Free tier: Lower limits
- Paid tiers: Higher limits
- Consider implementing retry logic with backoff
Terraform Enterprise Compatibility
This skill works with both:
- Terraform Cloud (app.terraform.io)
- Terraform Enterprise (self-hosted)
Ensure your TFE_TOKEN matches your target environment.
Testing and Troubleshooting
Pre-Execution Checklist
Before using this skill, verify:
TFE_TOKENis set:echo $TFE_TOKEN- Docker is running:
docker --version - MCP server connectivity:
docker run -i --rm -e TFE_TOKEN=$TFE_TOKEN hashicorp/terraform-mcp-server
Common Issues
"Connection refused":
- Check Docker is running
- Verify MCP server starts correctly
- Check network connectivity
"Authentication failed":
- Verify
TFE_TOKENis set and valid - Check token has required permissions
- Ensure token matches Terraform Cloud/Enterprise instance
"Type errors":
- Use correct Input interface for each function
- Check string vs boolean types (e.g.,
auto_apply: "true"nottrue) - Verify all required parameters are provided
Version Information
- Skill Version: 1.0.0
- Dependencies: Docker, Node.js (optional for local TypeScript execution)
- MCP Server: hashicorp/terraform-mcp-server (Docker image)
- Auto-Generated: This skill was auto-generated by mcp-to-claude-skill
Contributing to This Skill
When updating this skill:
- Keep wrapper functions in sync - If MCP server API changes, regenerate wrappers
- Update documentation - Ensure SKILL.md reflects current capabilities
- Test all examples - Verify code examples work with current MCP server
- Maintain security guidelines - Never include actual tokens in examples
- Keep type definitions accurate - TypeScript interfaces should match JSON Schema
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

