agentleFS
hashi-demo-labhashi-demo-lab/claude-skill-hcp-terraform/terraform-stacks/CLAUDE.md

claude-skill-hcp-terraform / terraform-stacks

CLAUDE.md4 starsChanged 13 months agoMITView on GitHub

This is a Claude Skill repository for HashiCorp Terraform Stacks - a specialized knowledge base that provides comprehensive documentation and guidance for working with Terraform Stacks configurations. This is not a traditional software project with executable code, but rather a documentation repository structured as a skill module for Claude AI assistants. Purpose: Enable Claude to help users create, modify, validate, and troubleshoot Terraform Stack configurations (.tfcomponent.hcl and .tfdeploy.hcl files), manage multi-region/multi-environment infrastructure, and understand Terraform Stacks syntax and best practices.

  • Commits and pushes

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

21 rules. About 0 are common, 18 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈18

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    [SKILL.md](SKILL.md): - Start here for high-level concepts, syntax overview, CLI commands, common patterns, and troubleshooting

    line 29
  2. Distinctive:

    All files must be at root level (processed in dependency order)

    line 78
  3. Distinctive:

    Each deployment has isolated state: - No shared state between deployments

    line 99
  4. Distinctive:

    Dependencies are auto-inferred: - When components reference other component outputs

    line 100
  5. Distinctive:

    Deployment groups are essential: - Always organize deployments into deployment groups, even single deployments.

    line 102
  6. Distinctive:

    Best Practice: Every deployment should be organized into a deployment group, even if it's the only deployment in the Stack.

    line 123
  7. Very specific:

    Use assume_role_with_web_identity in AWS provider config

    line 142
  8. Distinctive:

    After successful destruction, remove the deployment block from configuration

    line 149
  9. Very specific:

    Solution: All provider configurations must be at Stack level in .tfcomponent.hcl files

    line 163
  10. Distinctive:

    Follow these naming patterns for clarity:

    line 176
  11. Distinctive:

    All files are processed together by HCP Terraform, so the naming is for human organization only.

    line 186
  12. Distinctive:

    No compilation or build commands

    line 193
  13. Distinctive:

    No package manager or dependencies

    line 194
  14. Distinctive:

    No Docker or containerization

    line 196
  15. Distinctive:

    Update examples when syntax changes: - All code examples must remain valid and working

    line 203
  16. Distinctive:

    Test HCL syntax accuracy: - Ensure all code blocks use correct Terraform Stacks HCL syntax (not regular Terraform)

    line 205
  17. Distinctive:

    Include deployment groups in all examples: - Every example with deployments must include corresponding deployment_group blocks, even for …

    line 206
  18. Distinctive:

    Use Git for all changes:

    line 210
  19. Distinctive:

    All Terraform Stacks code examples use HCL syntax:

    line 222
  20. Distinctive:

    When referencing syntax details, point to specific files:

    line 241
  21. Distinctive:

    Use these exact terms consistently:

    line 248

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

This is a Claude Skill repository for HashiCorp Terraform Stacks - a specialized knowledge base that provides comprehensive documentation and guidance for working with Terraform Stacks configurations. This is not a traditional software project with executable code, but rather a documentation repository structured as a skill module for Claude AI assistants.

Purpose: Enable Claude to help users create, modify, validate, and troubleshoot Terraform Stack configurations (.tfcomponent.hcl and .tfdeploy.hcl files), manage multi-region/multi-environment infrastructure, and understand Terraform Stacks syntax and best practices.

Repository Structure

claude-skill-terraform-stacks/
├── README.md                         # Brief project description (2 lines)
├── SKILL.md                          # Main comprehensive guide (580 lines)
└── references/                       # Detailed reference documentation
    ├── component-blocks.md           # Component block specification (649 lines)
    ├── deployment-blocks.md          # Deployment block specification (1009 lines)
    └── examples.md                   # Complete working examples (1529 lines)

Total: 3,767 lines of documentation organized into focused modules.

Documentation Architecture

Core Documentation Flow

  1. SKILL.md - Start here for high-level concepts, syntax overview, CLI commands, common patterns, and troubleshooting
  2. references/component-blocks.md - Deep dive into component configuration syntax for .tfcomponent.hcl files
  3. references/deployment-blocks.md - Deep dive into deployment configuration syntax for .tfdeploy.hcl files
  4. references/examples.md - Complete working examples from simple to complex scenarios

Content Organization

SKILL.md covers:

  • Core concepts (Stack, Component, Deployment, Stack Language)
  • File structure and organization
  • Configuration blocks: variables, providers, components, outputs, locals, removed blocks
  • Deployment configuration syntax
  • CLI commands (terraform stacks validate, plan, apply)
  • Common patterns (multi-region, component dependencies)
  • Best practices and troubleshooting

references/component-blocks.md covers:

  • Complete syntax reference for all component configuration blocks
  • Detailed argument specifications with types and constraints
  • Code examples for each block type
  • Key differences from traditional Terraform syntax

references/deployment-blocks.md covers:

  • Complete syntax reference for all deployment configuration blocks
  • Identity token configurations (OIDC)
  • Deployment groups and auto-approval rules
  • Linked Stacks (publish outputs and upstream inputs)
  • Cloud provider-specific configurations (AWS, Azure, GCP)

references/examples.md covers:

  • Simple single-region Stack (with deployment group)
  • Stack with private registry modules
  • Multi-environment Stack (dev/staging/prod with deployment groups)
  • Multi-region Stack with regional provider configurations
  • Linked Stacks with cross-stack dependencies
  • Multi-cloud Stack (AWS + Azure)
  • Complete AWS production Stack with all features
  • Destroying deployments safely

Key Terraform Stacks Concepts

Stack Language vs Traditional Terraform

Terraform Stacks use a separate HCL-based language distinct from traditional Terraform:

  • Different file extensions: .tfcomponent.hcl (components), .tfdeploy.hcl (deployments)
  • Different block syntax for providers (use for_each, aliases in headers, config blocks)
  • Components wrap modules (modules cannot contain provider blocks)
  • Outputs and variables require type argument
  • All files must be at root level (processed in dependency order)

Component Module Sources

Components can reference modules from multiple source types:

  • Local paths: ./modules/vpc or ../shared-modules/networking
  • Public registry: terraform-aws-modules/vpc/aws (format: <NAMESPACE>/<NAME>/<PROVIDER>)
  • Private registry: app.terraform.io/my-org/vpc/aws (format: <HOSTNAME>/<ORG>/<MODULE>/<PROVIDER>)
    • HCP Terraform SaaS: Use app.terraform.io
    • Terraform Enterprise: Use your instance hostname
    • Generic hostname: Use localterraform.com for multi-instance deployments
  • Git repositories: git::https://github.com/org/repo.git//modules/vpc?ref=v1.0.0
  • HTTP/HTTPS archives: https://example.com/modules/vpc.tar.gz

The version argument is supported only for registry sources (public and private). See references/component-blocks.md for complete details.

Critical Architecture Points

  1. Components are abstractions around modules - Each component specifies a source module, inputs, and providers
  2. Deployments are instances of the entire Stack - Used for different environments, regions, or accounts
  3. Each deployment has isolated state - No shared state between deployments
  4. Dependencies are auto-inferred - When components reference other component outputs
  5. Provider configurations support for_each - Enable multi-region patterns with single configuration
  6. Deployment groups are essential - Always organize deployments into deployment groups, even single deployments. This enables auto-approval rules, maintains consistency, and provides a foundation for scaling

Common Scenarios and Patterns

When Users Ask About Multi-Region Infrastructure

Guide them to use:

  • for_each on provider blocks to create regional providers
  • for_each on component blocks to deploy per region
  • Each region gets its own provider instance and component instance

See SKILL.md lines 442-476 for the complete pattern.

When Users Ask About Multi-Environment Deployments

Guide them to create:

  • Multiple deployment blocks (one per environment)
  • Each deployment gets its own inputs and isolated state
  • Always create deployment groups to organize deployments (even for single deployments)
  • Deployment groups enable auto-approval rules and provide consistent configuration patterns

Best Practice: Every deployment should be organized into a deployment group, even if it's the only deployment in the Stack. This establishes a consistent pattern and enables future scaling.

See references/examples.md for multi-environment example.

When Users Ask About Cross-Stack Dependencies

Guide them to use:

  • publish_output blocks in the source Stack (exports values)
  • upstream_input blocks in the dependent Stack (imports values)
  • Reference upstream inputs in deployment inputs

See SKILL.md lines 375-407 for syntax.

When Users Ask About OIDC Authentication

Guide them to use:

  • identity_token blocks in .tfdeploy.hcl with appropriate audience
  • Reference token via identity_token.<name>.jwt
  • Pass token to provider configuration in deployment inputs
  • Use assume_role_with_web_identity in AWS provider config

When Users Ask About Destroying/Removing Deployments

Guide them to:

  1. Set destroy = true in the deployment block
  2. Apply the plan through HCP Terraform (this destroys all resources)
  3. After successful destruction, remove the deployment block from configuration

Important: Using destroy = true ensures provider authentication is retained during resource destruction. See references/deployment-blocks.md lines 173-196 and references/examples.md "Destroying Deployments" section.

Common Errors and Solutions

"Deprecated filename usage" Warning

Issue: Files use .tfcomponent.hcl extension Solution: Rename to .tfcomponent.hcl for component files; keep .tfdeploy.hcl for deployments

Provider Configuration Errors

Issue: Providers defined inside modules Solution: All provider configurations must be at Stack level in .tfcomponent.hcl files

Circular Dependencies

Issue: Component A references Component B, and B references A Solution: Refactor to break circular reference or introduce intermediate component

Maximum Deployments Limit

HCP Terraform supports maximum 20 deployments per Stack. For more instances, use multiple Stacks or for_each within components.

File Naming Conventions

Follow these naming patterns for clarity:

variables.tfcomponent.hcl      # Variable declarations
providers.tfcomponent.hcl      # Provider configurations
components.tfcomponent.hcl     # Component definitions
outputs.tfcomponent.hcl        # Stack outputs
deployments.tfdeploy.hcl       # Deployment definitions

All files are processed together by HCP Terraform, so the naming is for human organization only.

How to Work with This Repository

No Build System

This is a documentation-only repository:

  • No compilation or build commands
  • No package manager or dependencies
  • No automated tests
  • No Docker or containerization

Making Changes

When updating documentation:

  1. Maintain consistency across files - Changes to syntax should be reflected in SKILL.md, appropriate references/ file, and examples.md
  2. Update examples when syntax changes - All code examples must remain valid and working
  3. Keep the architecture accurate - The "big picture" concepts in SKILL.md must align with detailed specs in references/
  4. Test HCL syntax accuracy - Ensure all code blocks use correct Terraform Stacks HCL syntax (not regular Terraform)
  5. Include deployment groups in all examples - Every example with deployments must include corresponding deployment_group blocks, even for single deployments

Version Control

Use Git for all changes:

git status                    # Check current changes
git add <files>              # Stage changes
git commit -m "message"      # Commit changes
git push                     # Push to remote

Documentation Style Guide

Code Blocks

All Terraform Stacks code examples use HCL syntax:

# Correct block structure
component "example" {
  source = "./modules/example"

  inputs = {
    key = value
  }

  providers = {
    aws = provider.aws.this
  }
}

File References

When referencing syntax details, point to specific files:

  • Detailed component syntax → references/component-blocks.md
  • Detailed deployment syntax → references/deployment-blocks.md
  • Working examples → references/examples.md

Terminology Consistency

Use these exact terms consistently:

  • Stack (not "stack configuration" or "terraform stack")
  • Component (not "module" - modules are what components wrap)
  • Deployment (not "environment" - deployments can represent environments)
  • Stack Language (not "HCL" - it's a separate language based on HCL)

CLI Commands (Terraform Stacks)

# Generate provider lock file
terraform stacks providers lock

# Validate Stack configuration
terraform stacks validate

# Plan specific deployment
terraform stacks plan --deployment=<name>

# Apply specific deployment
terraform stacks apply --deployment=<name>

Note: These are not regular terraform commands - they are terraform stacks subcommands specific to Terraform Stacks.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.