Terraform Stacks
HashiCorpOfficialPublished by HashiCorp
- Skill
- Tool integration
- Cloud and DevOps
- MPL-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Terraform Stacks provides a declarative orchestration layer above traditional Terraform modules, enabling the management of complex infrastructure across multiple environments, regions, and cloud accounts. It introduces a specialized HCL-based configuration language using .tfcomponent.hcl and .tfdeploy.hcl files to define components, providers, and deployment instances. This skill covers the full lifecycle of Stacks, including configuration, dependency management, provider configuration, and deployment monitoring via the CLI or HCP Terraform API.
What it does
- Defines infrastructure units as components referencing local, registry, or Git-based modules.
- Orchestrates multi-region and multi-environment deployments within a single Stack.
- Manages provider configurations with support for for_each and workload identity authentication.
- Links multiple Stacks together using published outputs and upstream inputs.
- Automates deployment workflows and monitoring through HCP Terraform integration.
- Provides patterns for safe component removal and deferred changes.
When to use it
- When you need to manage complex, multi-component infrastructure at scale.
- When you require consistent infrastructure deployments across multiple environments or regions.
- When you want to move beyond individual Terraform modules to a higher-level orchestration layer.
- When implementing OIDC-based workload identity for secure, temporary cloud credentials.
- When you need to link separate infrastructure stacks together in a dependency chain.
Advantages
- Simplifies management of large-scale infrastructure by grouping related components.
- Reduces reliance on long-lived static credentials through native workload identity support.
- Provides clear separation between component definitions and deployment-specific inputs.
- Enables automated deployment pipelines with built-in dependency inference.
- Supports advanced patterns like multi-region deployments and cross-stack output sharing.
Usage examples
- “How do I define a component in a Terraform Stack that uses a module from the public registry?”
- The agent provides a component block example using the source argument with the registry path, specifying inputs and mapping providers.
- “What is the best way to handle AWS credentials in a Stack without using static keys?”
- The agent explains the workload identity pattern, showing how to configure an identity_token block and use assume_role_with_web_identity in the provider config.
- “How can I monitor the status of a deployment run programmatically?”
- The agent provides the API endpoints for retrieving deployment group summaries and run status, including the necessary headers for authentication.
- “How do I remove a component from an existing Stack?”
- The agent details the use of the removed block, explaining that it requires the component's providers to be defined to safely process the removal.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/hashicorp/terraform-stacks/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip terraform-stacks.zip -d .agents/skills
Documentation by HashiCorp
Terraform Stacks
Terraform Stacks simplify infrastructure provisioning and management at scale by providing a configuration layer above traditional Terraform modules. Stacks enable declarative orchestration of multiple components across environments, regions, and cloud accounts.
Core Concepts
Stack: A complete unit of infrastructure composed of components and deployments that can be managed together.
Component: An abstraction around a Terraform module that defines infrastructure pieces. Each component specifies a source module, inputs, and providers.
Deployment: An instance of all components in a stack with specific input values. Use deployments for different environments (dev/staging/prod), regions, or cloud accounts.
Stack Language: A separate HCL-based language (not regular Terraform HCL) with distinct blocks and file extensions.
File Structure
Terraform Stacks use specific file extensions:
Component configuration:
.tfcomponent.hclDeployment configuration:
.tfdeploy.hclProvider lock file:
.terraform.lock.hcl(generated by CLI)
All configuration files must be at the root level of the Stack repository. HCP Terraform processes all files in dependency order.
Recommended File Organization
my-stack/
├── .terraform-version # The required Terraform version for this Stack
├── 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
├── .terraform.lock.hcl # Provider lock file (generated)
└── modules/ # Local modules (optional - only if using local modules)
├── s3/
└── compute/Note: The modules/ directory is only required when using local module sources. Components can reference modules from:
Local file paths:
./modules/vpcPublic registry:
terraform-aws-modules/vpc/awsPrivate registry:
app.terraform.io/<org-name>/vpc/awsGit:
git::https://github.com/org/repo.git//path?ref=v1.0.0
HCP Terraform processes all .tfcomponent.hcl and .tfdeploy.hcl files in dependency order.
Required Terraform version (.terraform-version)
Use Terraform v1.13.x or later to access the Stacks CLI plugin and to run terraform stacks CLI commands. Begin by adding a .terraform-version file to your Stack's root directory to specify the Terraform version required for your Stack. For example, the following file specifies Terraform v1.14.5:
1.14.5Component Configuration (.tfcomponent.hcl)
Variable Block
Declare input variables for the Stack configuration. Variables must define a type field and do not support the validation argument.
variable "aws_region" {
type = string
description = "AWS region for deployments"
default = "us-west-1"
}
variable "identity_token" {
type = string
description = "OIDC identity token"
ephemeral = true # Does not persist to state file
}
variable "instance_count" {
type = number
nullable = false
}Important: Use ephemeral = true for credentials and tokens (identity tokens, API keys, passwords) to prevent them from persisting in state files. Use stable for longer-lived values like license keys that need to persist across runs.
Required Providers Block
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.5.0"
}
}Provider Block
Provider blocks differ from traditional Terraform:
Support
for_eachmeta-argumentDefine aliases in the block header (not as an argument)
Accept configuration through a
configblock
Single Provider Configuration:
provider "aws" "this" {
config {
region = var.aws_region
assume_role_with_web_identity {
role_arn = var.role_arn
web_identity_token = var.identity_token
}
}
}Multiple Provider Configurations with for_each:
provider "aws" "configurations" {
for_each = var.regions
config {
region = each.value
assume_role_with_web_identity {
role_arn = var.role_arn
web_identity_token = var.identity_token
}
}
}Authentication Best Practice: Use workload identity (OIDC) as the preferred authentication method for Stacks. This approach:
Avoids long-lived static credentials
Provides temporary, scoped credentials per deployment run
Integrates with cloud provider IAM (AWS IAM Roles, Azure Managed Identities, GCP Service Accounts)
Eliminates need for platform-managed environment variables
Configure workload identity using identity_token blocks and assume_role_with_web_identity in provider configuration. For detailed setup instructions for AWS, Azure, and GCP, see: https://developer.hashicorp.com/terraform/cloud-docs/dynamic-provider-credentials
Component Block
Each Stack requires at least one component block. Add a component for each module to include in the Stack. Components reference modules from local paths, registries, or Git.
component "vpc" {
source = "app.terraform.io/my-org/vpc/aws" # Local, registry, or Git URL
version = "2.1.0" # For registry modules
inputs = {
cidr_block = var.vpc_cidr
name_prefix = var.name_prefix
}
providers = {
aws = provider.aws.this
}
}See references/component-blocks.md for examples of dependencies, for_each, public registry modules, Git sources, and more.
Key Points:
Reference outputs:
component.<name>.<output>orcomponent.<name>[key].<output>for for_eachDependencies inferred automatically from component references
Aggregate with for expressions:
[for x in component.s3 : x.bucket_name]For components with
for_each, reference specific instances:component.<name>[each.value].<output>Provider references are normal values:
provider.<type>.<alias>orprovider.<type>.<alias>[each.value]
Output Block
Outputs require a type argument and do not support preconditions:
output "vpc_id" {
type = string
description = "VPC ID"
value = component.vpc.vpc_id
}
output "endpoint_urls" {
type = map(string)
value = {
for region, comp in component.api : region => comp.endpoint_url
}
sensitive = false
}Locals Block
Locals blocks work the same in both .tfcomponent.hcl and .tfdeploy.hcl files:
locals {
common_tags = {
Environment = var.environment
ManagedBy = "Terraform Stacks"
Project = var.project_name
}
region_config = {
for region in var.regions : region => {
name_suffix = "${var.environment}-${region}"
}
}
}Removed Block
Use to safely remove components from a Stack. HCP Terraform requires the component's providers to remove it.
removed {
from = component.old_component
source = "./modules/old-module"
providers = {
aws = provider.aws.this
}
}Deployment Configuration (.tfdeploy.hcl)
Identity Token Block
Generate JWT tokens for OIDC authentication with cloud providers:
identity_token "aws" {
audience = ["aws.workload.identity"]
}
identity_token "azure" {
audience = ["api://AzureADTokenExchange"]
}Reference tokens in deployments using identity_token.<name>.jwt
Store Block
Access HCP Terraform variable sets within Stack deployments:
store "varset" "aws_credentials" {
id = "varset-ABC123" # Alternatively use: name = "varset_name"
source = "tfc-cloud-shared"
category = "terraform" # Alternatively use: category = "env" for environment variables
}
deployment "production" {
inputs = {
aws_access_key = store.varset.aws_credentials.AWS_ACCESS_KEY_ID
}
}Use to centralize credentials and share variables across Stacks. See references/deployment-blocks.md for details.
Deployment Block
Define deployment instances (minimum 1, maximum 20 per Stack):
deployment "production" {
inputs = {
aws_region = "us-west-1"
instance_count = 3
role_arn = local.role_arn
identity_token = identity_token.aws.jwt
}
}
# Create multiple deployments for different environments
deployment "development" {
inputs = {
aws_region = "us-east-1"
instance_count = 1
name_suffix = "dev"
role_arn = local.role_arn
identity_token = identity_token.aws.jwt
}
}To destroy a deployment: Set destroy = true, upload configuration, approve destroy run, then remove the deployment block. See references/deployment-blocks.md for details.
Deployment Group Block
Group deployments together for shared settings (HCP Terraform Premium tier feature). Free/standard tiers use default groups named {deployment-name}_default.
deployment_group "canary" {
auto_approve_checks = [deployment_auto_approve.safe_changes]
}
deployment "dev" {
inputs = { /* ... */ }
deployment_group = deployment_group.canary
}Multiple deployments can reference the same group. See references/deployment-blocks.md for details.
Deployment Auto-Approve Block
Define rules to automatically approve deployment plans (HCP Terraform Premium tier feature):
deployment_auto_approve "safe_changes" {
deployment_group = deployment_group.canary
check {
condition = context.plan.changes.remove == 0
reason = "Cannot auto-approve plans with resource deletions"
}
}Available context variables: context.plan.applyable, context.plan.changes.add/change/remove/total, context.success
Note: orchestrate blocks are deprecated. Use deployment_group and deployment_auto_approve instead.
See references/deployment-blocks.md for all context variables and patterns.
Publish Output and Upstream Input Blocks
Link Stacks together by publishing outputs from one Stack and consuming them in another:
# In network Stack - publish outputs
publish_output "vpc_id_network" {
type = string
value = deployment.network.vpc_id
}
# In application Stack - consume outputs
upstream_input "network_stack" {
type = "stack"
source = "app.terraform.io/my-org/my-project/networking-stack"
}
deployment "app" {
inputs = {
vpc_id = upstream_input.network_stack.vpc_id_network
}
}See references/linked-stacks.md for complete documentation and examples.
Terraform Stacks CLI
Note: Terraform Stacks is Generally Available (GA) as of Terraform CLI v1.13+. Stacks now count toward Resources Under Management (RUM) for HCP Terraform billing.
Initialize and Validate
terraform stacks init # Download providers, modules, generate lock file
terraform stacks providers-lock # Regenerate lock file (add platforms if needed)
terraform stacks validate # Check syntax without uploadingDeployment Workflow
Important: No plan or apply commands. Upload configuration triggers deployment runs automatically.
# 1. Upload configuration (triggers deployment runs)
terraform stacks configuration upload
# 2. Monitor deployments
terraform stacks deployment-run list # List runs (non-interactive)
terraform stacks deployment-group watch -deployment-group=... # Stream status updates
# 3. Approve deployments (if auto-approve not configured)
terraform stacks deployment-run approve-all-plans -deployment-run-id=...
terraform stacks deployment-group approve-all-plans -deployment-group=...
terraform stacks deployment-run cancel -deployment-run-id=... # Cancel if neededConfiguration Management
terraform stacks configuration list # List configuration versions
terraform stacks configuration fetch -configuration-id=... # Download configuration
terraform stacks configuration watch # Monitor upload statusOther Commands
terraform stacks create # Create new Stack (interactive)
terraform stacks fmt # Format Stack files
terraform stacks list # Show all Stacks
terraform stacks version # Display version
terraform stacks deployment-group rerun -deployment-group=... # Rerun deploymentMonitoring Deployments with HCP Terraform API
For programmatic monitoring in automation, CI/CD, or non-interactive environments (like AI agents), use the HCP Terraform API instead of CLI watch commands. The API provides endpoints for:
Configuration status and validation
Deployment group summaries
Deployment run status
Deployment step details (plan/apply)
Error diagnostics with file locations and code snippets
Stack outputs via artifacts endpoint
Key points:
CLI watch commands stream indefinitely and don't work in automation
Use artifacts endpoint to retrieve Stack outputs:
GET /api/v2/stack-deployment-steps/{step-id}/artifacts?name=apply-descriptionDiagnostics endpoint requires
stack_deployment_step_idquery parameterArtifacts endpoint returns HTTP 307 redirect (use
curl -L)
For complete API workflow, authentication, polling best practices, and example scripts, see references/api-monitoring.md.
Common Patterns
Component Dependencies: Dependencies are automatically inferred when one component references another's output (e.g., subnet_ids = component.vpc.private_subnet_ids).
Multi-Region Deployment: Use for_each on providers and components to deploy across multiple regions. Each region gets its own provider configuration and component instances.
Deferred Changes: Stacks support deferred changes to handle dependencies where values are only known after apply. This enables complex multi-component deployments where some resources depend on runtime values from other components (cluster endpoints, generated passwords, etc.).
For complete examples including multi-region deployments, component dependencies, deferred changes patterns, and linked Stacks, see references/examples.md.
Best Practices
Component Granularity: Create components for logical infrastructure units that share a lifecycle
Module Compatibility:
Modules used with Stacks cannot include provider blocks (configure providers in Stack configuration)
Test public registry modules before using in production Stacks - some modules may have compatibility issues
Consider using raw resources for critical infrastructure if module compatibility is uncertain
Example: Some terraform-aws-modules versions have been found to have compatibility issues with Stacks (e.g., ALB and ECS modules)
State Isolation: Each deployment has its own isolated state
Input Variables: Use variables for values that differ across deployments; use locals for shared values
Provider Lock Files: Always generate and commit
.terraform.lock.hclto version controlNaming Conventions: Use descriptive names for components and deployments
Deployment Groups: You can organize deployments into deployment groups. Deployment groups enable auto-approval rules, logical organization, and provide a foundation for scaling. Deployment groups are an HCP Terraform Premium tier feature
Testing: Test Stack configurations in dev/staging deployments before production
Troubleshooting
Circular Dependencies: Refactor to break circular references or use intermediate components.
Deployment Destruction: Cannot destroy from UI. Set destroy = true in deployment block, upload configuration, and HCP Terraform creates a destroy run.
Empty Diagnostics: Add required stack_deployment_step_id query parameter to diagnostics API requests.
Module Compatibility: Test public registry modules before production use. Some modules may have compatibility issues with Stacks.
References
For detailed documentation, see:
references/component-blocks.md- Complete component block reference with all arguments and syntaxreferences/deployment-blocks.md- Complete deployment block reference with all configuration optionsreferences/linked-stacks.md- Publish outputs and upstream inputs for linking Stacks togetherreferences/examples.md- Complete working examples for multi-region and component dependenciesreferences/api-monitoring.md- Full API workflow for programmatic monitoring and automationreferences/troubleshooting.md- Detailed troubleshooting guide for common issues and solutions
Files
- ATTRIBUTION.mdAdded by AutoGineer900 B
- LICENSELicence file added by AutoGineer16.3 KiB
- SKILL.md16.9 KiB
- references/api-monitoring.md16.2 KiB
- references/component-blocks.md9.9 KiB
- references/deployment-blocks.md8.7 KiB
- references/examples.md30.0 KiB
- references/linked-stacks.md4.2 KiB
- references/troubleshooting.md16.3 KiB
references/troubleshooting.md
Troubleshooting Reference
Common issues and solutions when working with Terraform Stacks.
Table of Contents
Configuration Issues
Deployment Issues
Provider and Authentication Issues
Module Compatibility Issues
State and Dependency Issues
API and CLI Issues
Configuration Issues
Circular Dependencies
Issue: Component A references Component B, and Component B references Component A.
Error Message:
Error: Cycle detected in component dependenciesSolutions:
Break the circular reference by refactoring components:
# Before (circular dependency)
component "vpc" {
source = "./modules/vpc"
inputs = {
security_group_id = component.app.security_group_id # References app
}
}
component "app" {
source = "./modules/app"
inputs = {
vpc_id = component.vpc.vpc_id # References vpc
}
}
# After (broken circular reference)
component "vpc" {
source = "./modules/vpc"
inputs = {
# Remove reference to app
}
}
component "security_group" {
source = "./modules/security-group"
inputs = {
vpc_id = component.vpc.vpc_id
}
}
component "app" {
source = "./modules/app"
inputs = {
vpc_id = component.vpc.vpc_id
security_group_id = component.security_group.id
}
}Use intermediate components to break the dependency chain
Refactor modules to remove the circular dependency at the module level
Validation Errors on Variables
Issue: Variable block validation errors during terraform stacks validate.
Error Message:
Error: Unsupported argument
on variables.tfcomponent.hcl line 5:
5: validation {
Validation blocks are not supported in Stack configurationsSolution: Remove validation blocks from variable declarations. Stacks do not support validation blocks:
# Incorrect
variable "instance_count" {
type = number
validation {
condition = var.instance_count > 0
error_message = "Instance count must be positive"
}
}
# Correct
variable "instance_count" {
type = number
description = "Number of instances (must be positive)"
}Move validation logic into the underlying modules if needed.
Missing Type in Variable Declarations
Issue: Variables fail validation when type is not specified.
Error Message:
Error: Missing required argument
on variables.tfcomponent.hcl line 3:
3: variable "region" {
The argument "type" is required in Stack variable declarationsSolution: Always specify type for variables - it's required in Stacks (unlike traditional Terraform):
# Incorrect
variable "region" {
default = "us-west-1"
}
# Correct
variable "region" {
type = string
default = "us-west-1"
}Provider Configuration in Modules
Issue: Modules with embedded provider blocks cause errors.
Error Message:
Error: Provider configuration not allowed in module
Modules used with Terraform Stacks cannot contain provider blocksSolution:
Remove provider blocks from modules - configure providers in Stack configuration instead
Use modules that don't contain provider blocks (most public registry modules are compatible)
Fork and modify modules if necessary to remove provider blocks
Deployment Issues
Cannot Destroy Deployment from UI
Issue: The HCP Terraform UI doesn't provide an option to destroy Stack deployments.
Why: Stack deployment destruction is only available through configuration, not the UI.
Solution: Set destroy = true in the deployment block and upload the configuration:
deployment "old_environment" {
inputs = {
aws_region = "us-west-1"
instance_count = 2
role_arn = local.role_arn
identity_token = identity_token.aws.jwt
}
destroy = true # Marks deployment for destruction
}Workflow:
Add
destroy = trueto the deployment blockRun
terraform stacks configuration uploadHCP Terraform creates a destroy run automatically
Approve the destroy run (if auto-approve is not configured)
After destruction completes, remove the deployment block entirely
Upload configuration again to clean up the deployment definition
Important: You cannot destroy deployments from the UI. This is by design to prevent accidental destruction.
Deployment Stuck in "Planning" State
Issue: Deployment remains in "planning" state indefinitely.
Possible Causes:
Provider authentication failed - Check OIDC configuration and IAM roles
Module download failed - Verify module sources are accessible
Provider version conflict - Check
.terraform.lock.hclmatches required providers
Diagnosis:
# Get deployment step diagnostics
terraform stacks deployment-run list
# Note the run ID, then:
curl -s -H "Authorization: Bearer $TOKEN" \
"https://app.terraform.io/api/v2/stack-deployment-runs/{run-id}/stack-deployment-steps" | \
jq '.data[] | {id, status: .attributes.status, component: .attributes["component-name"]}'Solutions:
Check diagnostics for the stuck step
Verify provider authentication is configured correctly
Ensure all module sources are accessible
Check provider lock file matches required providers
Deployment Requires Approval But No Approval Prompt
Issue: Deployment is waiting for approval but CLI doesn't show approval prompt.
Why: CLI monitoring commands are non-blocking and don't automatically prompt for approval.
Solution:
Option 1: Approve via CLI
# Approve all pending plans in a deployment run
terraform stacks deployment-run approve-all-plans -deployment-run-id=sdr-ABC123
# Or approve all plans in a deployment group
terraform stacks deployment-group approve-all-plans -deployment-group=canaryOption 2: Configure auto-approve (Premium feature)
deployment_auto_approve "safe_changes" {
deployment_group = deployment_group.canary
check {
condition = context.plan.applyable
reason = "Plan must be successful"
}
}Provider and Authentication Issues
OIDC Authentication Failing
Issue: Provider authentication fails with OIDC/workload identity.
Error Messages:
Error: Error assuming role with web identity
Error: Failed to retrieve credentials
Error: Invalid identity tokenDiagnosis Steps:
Verify identity token configuration:
# Check identity_token block exists
identity_token "aws" {
audience = ["aws.workload.identity"]
}
# Check deployment references the token
deployment "production" {
inputs = {
identity_token = identity_token.aws.jwt
}
}Verify provider configuration:
provider "aws" "this" {
config {
region = var.aws_region
assume_role_with_web_identity {
role_arn = var.role_arn
web_identity_token = var.identity_token
}
}
}Check IAM role trust policy:
AWS - Verify trust policy includes HCP Terraform:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<account-id>:oidc-provider/app.terraform.io"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"app.terraform.io:aud": "aws.workload.identity"
},
"StringLike": {
"app.terraform.io:sub": "organization:<org-name>:project:<project-name>:stack:<stack-name>:deployment:<deployment-name>"
}
}
}
]
}Azure - Verify federated credential:
Application ID matches the one in provider configuration
Subject matches:
organization:<org>:project:<project>:stack:<stack>:deployment:<deployment>Issuer is
https://app.terraform.io
GCP - Verify workload identity pool:
Provider configuration includes correct workload identity provider
Service account has necessary IAM permissions
Attribute mapping includes
google.subjectfrom token claims
Solutions:
Fix IAM role trust policy to include correct HCP Terraform OIDC provider
Ensure audience matches between identity_token block and IAM trust policy
Verify subject pattern matches your organization/project/stack/deployment names
Check that the role_arn is correct in provider configuration
Provider Version Lock File Issues
Issue: Provider version conflicts or "could not retrieve provider" errors.
Error Messages:
Error: Failed to install provider
Error: Provider version not found
Error: Checksum mismatch for providerSolutions:
Regenerate provider lock file:
terraform stacks providers-lockAdd additional platforms (if deploying from different OS):
terraform stacks providers-lock \
-platform=linux_amd64 \
-platform=darwin_amd64 \
-platform=darwin_arm64Verify required_providers block:
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.7.0" # Ensure version constraint is valid
}
}Commit
.terraform.lock.hclto version control
Module Compatibility Issues
Public Registry Module Errors
Issue: Modules from the Terraform public registry cause errors during plan or apply.
Common Errors:
Error: Unsupported attribute
Error: Invalid reference
Error: Missing required argumentKnown Problematic Modules:
terraform-aws-modules/alb/aws- Some versions have compatibility issuesterraform-aws-modules/ecs-service/aws- May have issues with certain configurations
Solutions:
Test modules in dev deployment first before using in production
Check module compatibility by reviewing recent issues on the module repository
Use specific module versions rather than latest:
component "alb" {
source = "terraform-aws-modules/alb/aws"
version = "8.7.0" # Use specific version known to work
# ...
}Consider using raw resources for critical infrastructure:
# Instead of using a module that has issues
component "alb" {
source = "./modules/alb" # Create local module with raw resources
# ...
}Fork and fix modules if you have the resources to maintain them
Report compatibility issues to module maintainers
Local Module Not Found
Issue: Stack can't find local module sources.
Error Message:
Error: Module not found
Could not load module ./modules/vpcSolutions:
Verify module path is relative to Stack root:
# Correct
component "vpc" {
source = "./modules/vpc"
}
# Incorrect (absolute paths don't work)
component "vpc" {
source = "/Users/username/project/modules/vpc"
}Ensure module directory exists with proper structure:
my-stack/
├── components.tfcomponent.hcl
└── modules/
└── vpc/
├── main.tf
├── variables.tf
└── outputs.tfCheck file permissions on module directories
State and Dependency Issues
Component Output Not Available
Issue: Component output is not available to referencing component.
Error Message:
Error: Reference to unknown component
Component "vpc" has not been definedSolutions:
Verify component exists in configuration:
component "vpc" {
source = "./modules/vpc"
# Must define component before referencing it
}
component "app" {
source = "./modules/app"
inputs = {
vpc_id = component.vpc.vpc_id # Now valid
}
}Check output is defined in module:
# In modules/vpc/outputs.tf
output "vpc_id" {
value = aws_vpc.main.id
}For components with for_each, reference specific instance:
component "regional" {
for_each = var.regions
# ...
}
component "app" {
inputs = {
# Correct - reference specific instance
vpc_id = component.regional["us-west-1"].vpc_id
# Incorrect - can't reference for_each component directly
# vpc_id = component.regional.vpc_id
}
}Deferred Changes Not Converging
Issue: Deployment with deferred changes doesn't complete after multiple iterations.
Error Message:
Error: Maximum deferred change iterations reachedCause: Dependency cycle or values that never stabilize.
Solutions:
Review component dependencies for logical cycles
Check for computed values that change on every run
Refactor to break dependency chain
Consider multi-stage deployments if resources truly can't be created together
API and CLI Issues
Empty Diagnostics Response
Issue: API request for diagnostics returns empty results.
Request:
curl "https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}/stack-diagnostics"Response:
{
"data": []
}Solution: Add required stack_deployment_step_id query parameter:
curl "https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}/stack-diagnostics?stack_deployment_step_id={step-id}"Cannot Retrieve Stack Outputs
Issue: No CLI command to retrieve Stack outputs after deployment.
Why: Currently no direct CLI command for outputs retrieval.
Solution: Use the artifacts API endpoint:
# Get final apply step ID first
APPLY_STEP=$(terraform stacks deployment-run list --json | \
jq -r '.[0].deployment_steps[] | select(.operation_type == "apply") | .id' | tail -1)
# Get outputs
curl -L -s -H "Authorization: Bearer $TOKEN" \
"https://app.terraform.io/api/v2/stack-deployment-steps/$APPLY_STEP/artifacts?name=apply-description" | \
jq -r '.outputs | to_entries | .[] | "\(.key): \(.value.change.after)"'CLI Watch Commands Hang in CI/CD
Issue: Commands like terraform stacks deployment-run watch never return in CI/CD pipelines.
Why: Watch commands stream output indefinitely and are designed for interactive use.
Solution: Use API polling instead of watch commands. See api-monitoring.md for complete workflow.
Artifacts Endpoint Returns 404
Issue: Request to artifacts endpoint returns 404 Not Found.
Possible Causes:
Step hasn't completed yet - wait for step status to be "completed"
Wrong artifact name - use one of: plan-description, plan-debug-log, apply-description, apply-debug-log
Invalid step ID - verify step ID from deployment-steps endpoint
Solution:
# Check step status first
curl -s -H "Authorization: Bearer $TOKEN" \
"https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}" | \
jq '.data.attributes.status'
# Only request artifacts when status is "completed"
if [ "$STATUS" = "completed" ]; then
curl -L -H "Authorization: Bearer $TOKEN" \
"https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}/artifacts?name=apply-description"
fiHTTP 307 Redirect Not Followed
Issue: Artifacts endpoint returns redirect response instead of artifact content.
Why: The endpoint returns HTTP 307 redirect to the actual artifact URL.
Solution: Configure HTTP client to follow redirects:
# curl: Use -L flag
curl -L -H "Authorization: Bearer $TOKEN" \
"https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}/artifacts?name=apply-description"
# Python requests: allow_redirects=True (default)
import requests
response = requests.get(url, headers=headers, allow_redirects=True)
# Node.js fetch: redirect: 'follow' (default)
const response = await fetch(url, {
headers: headers,
redirect: 'follow'
});Getting Additional Help
Enable Debug Logging
For more detailed error information, enable debug logging:
# CLI commands
TF_LOG=DEBUG terraform stacks validate
TF_LOG=DEBUG terraform stacks configuration upload
# API artifacts
# Request the debug-log artifact instead of description
curl -L -H "Authorization: Bearer $TOKEN" \
"https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}/artifacts?name=apply-debug-log"Check HCP Terraform Status
If experiencing widespread issues, check HCP Terraform status page:
Review Configuration Version
List recent configurations to identify when issues started:
terraform stacks configuration listContact Support
For issues not covered here:
Gather relevant error messages and diagnostics
Note the configuration sequence number
Include deployment run IDs
Contact HashiCorp Support with details
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an API key, Needs a command-line tool
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- HashiCorp
- Publisher
- HashiCorp (Official)
- Source
- hashicorp/agent-skills · plugins/terraform/skills/terraform-stacks · commit 5e30fa5
- Licence
- Mozilla Public License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by HashiCorp or HashiCorp.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download terraform-stacks.zip