| name | hcptf-cli |
| description | Manage HCP Terraform resources using the hcptf command-line tool. Use when working with HCP Terraform, Terraform Cloud, Terraform Enterprise, workspaces, runs, organizations, stacks, registry modules/providers, or infrastructure automation tasks. |
HCP Terraform CLI (hcptf)
Use the CLI with workspace/run hierarchical commands and URL-style navigation.
When to Use This Skill
Use this skill when:
- Managing HCP Terraform workspaces, runs, or organizations
- Working with Terraform Stacks or private registry resources
- Automating infrastructure deployments
- Querying resource state across organizations
- User mentions "Terraform Cloud", "HCP Terraform", or "TFE"
Authentication
The CLI checks for credentials in this order:
TFE_TOKEN environment variable
HCPTF_TOKEN environment variable
~/.hcptfrc configuration file
~/.terraform.d/credentials.tfrc.json (shared with Terraform CLI)
Quick Setup
hcptf login
export TFE_TOKEN="your-token-here"
Command Structure
The CLI uses a hierarchical namespace structure for organization:
Hierarchical Commands
hcptf registry
hcptf registry module list -org=my-org
hcptf registry provider create -org=my-org -name=custom
hcptf registry provider version create -org=my-org -name=aws -version=3.1.1 -key-id=GPG_KEY
hcptf stack
hcptf stack list -org=my-org -project=prj-123
hcptf stack configuration list -stack-id=stk-123
hcptf stack deployment create -stack-id=stk-123
hcptf stack state list -stack-id=stk-123
hcptf explorer query -org=my-org -type=providers -sort=-version
Traditional Commands
hcptf workspace list -org=my-org
hcptf workspace create -org=my-org -name=staging
hcptf workspace read -org=my-org -name=staging
hcptf workspace run list -org=my-org -name=staging
hcptf workspace run create -org=my-org -name=staging -message="Deploy"
hcptf workspace run show -id=run-abc123
hcptf workspace run apply -id=run-abc123
hcptf workspace run cancel -id=run-abc123
hcptf workspace run discard -id=run-abc123
hcptf workspace run assessmentresult list -org=my-org -name=staging
hcptf workspace run assessmentresult read -id=asmtres-abc123 -show-drift
hcptf variable create -org=my-org -workspace=staging -key=region -value=us-east-1
hcptf variable create -org=my-org -workspace=staging \
-key=AWS_SECRET -value=secret -category=env -sensitive
URL-Style Navigation
For interactive exploration, use path-like syntax:
hcptf my-org
hcptf my-org workspaces
hcptf my-org projects
hcptf my-org teams
hcptf my-org my-workspace
hcptf my-org my-workspace runs
hcptf my-org my-workspace assessments
hcptf my-org my-workspace variables
hcptf my-org my-workspace state
hcptf my-org my-workspace runs run-abc123
hcptf my-org my-workspace runs run-abc123 apply
Common Workflows
Create Workspace and Deploy
hcptf workspace create -org=my-org -name=production \
-auto-apply=false \
-terraform-version=1.6.0
hcptf variable create -org=my-org -workspace=production \
-key=environment -value=prod
hcptf workspace run create -org=my-org -name=production \
-message="Initial deployment"
hcptf workspace run show -id=run-abc123
hcptf workspace run apply -id=run-abc123 -comment="Approved by team"
Manage Private Registry
hcptf registry module list -org=my-org
hcptf registry provider create -org=my-org \
-name=custom-aws \
-namespace=my-org
hcptf registry provider version create -org=my-org \
-name=custom-aws \
-version=1.0.0 \
-key-id=ABC123
hcptf registry provider platform create -org=my-org \
-name=custom-aws \
-version=1.0.0 \
-os=linux \
-arch=amd64 \
-filename=terraform-provider-custom-aws_1.0.0_linux_amd64.zip
Work with Stacks
hcptf stack list -org=my-org -project=prj-abc123
hcptf stack create -org=my-org \
-project=prj-abc123 \
-name=production-stack
hcptf stack configuration list -stack-id=stk-abc123
hcptf stack deployment create -stack-id=stk-abc123
hcptf stack deployment read -deployment-id=dep-abc123
hcptf stack state list -stack-id=stk-abc123
Query Resources with Explorer
hcptf explorer query -org=my-org \
-type=providers \
-sort=-version
hcptf explorer query -org=my-org \
-type=workspaces \
-filter="name:production"
hcptf explorer query -org=my-org \
-type=tf_versions \
-export-csv \
-output=versions.csv
Agent-Friendly Features
The CLI is designed to work well when driven by AI agents. Always use these features when automating with hcptf.
Schema Introspection
Before constructing commands, discover available flags as structured JSON:
hcptf schema workspace create
hcptf schema variable create
hcptf schema run apply
Returns JSON with flag names, types, required status, aliases, and defaults. Always use hcptf schema instead of parsing --help text.
Dry Run (validate without executing)
Always use -dry-run before mutations to validate inputs without making API calls:
hcptf workspace delete -org=my-org -name=staging -dry-run
hcptf variable create -org=my-org -workspace=prod -key=region -value=us-east-1 -dry-run
hcptf run apply -id=run-abc123 -dry-run
Returns JSON describing the planned action. No API call is made.
JSON Input for Mutations
Pass full API payloads instead of individual flags using -json-input:
hcptf variable create -org=my-org -workspace=prod \
-json-input='{"key":"region","value":"us-east-1","category":"terraform"}'
hcptf workspace create -org=my-org -json-input=@workspace.json
cat config.json | hcptf workspace create -org=my-org -json-input=-
Note: Routing flags like -org and -workspace are still required alongside -json-input.
Field Filtering
Limit output to specific fields with -fields to reduce response size:
hcptf workspace list -org=my-org -fields=Name,ID -output=json
hcptf workspace read -org=my-org -name=prod -fields=ID,Name,Status
hcptf variable create -org=my-org -workspace=prod -key=x -value=y -fields=ID,Key
Input Validation
All mutation commands validate inputs against common agent mistakes:
- Path traversal (
../) is rejected
- Query injection (
?, &) is rejected
- URL-encoded sequences (
%2f) are rejected
- Control characters are rejected
- Overly long strings are rejected
Recommended Agent Workflow
hcptf schema workspace create
hcptf workspace create -org=my-org -name=staging -dry-run
hcptf workspace create -org=my-org -name=staging -output=json -fields=ID,Name
hcptf workspace create -org=my-org \
-json-input='{"name":"staging","terraform-version":"1.6.0","auto-apply":false}' \
-output=json -fields=ID,Name
Output Formats
Table Output (Default)
hcptf workspace list -org=my-org
JSON Output (for scripting and agents)
hcptf workspace list -org=my-org -output=json
Filtered JSON Output
hcptf workspace list -org=my-org -output=json -fields=Name,ID,Status
Best Practices
-
Always use -dry-run before write/delete commands to confirm the action is correct before executing
-
Always confirm with user before write/delete commands — never auto-execute mutations without user approval
-
Use hcptf schema to discover flags — never guess flag names or parse help text
-
Use -output=json and -fields for automation — reduces output size and gives structured data
-
Use hierarchical commands for clarity
hcptf workspace run create for run workflows
hcptf workspace run assessmentresult list for drift workflows
-
Prefer explicit flags for automation
- Use
-org= and -name= in scripts
-workspace= remains available as alias
- URL-style is great for interactive use
-
Check status before applying
hcptf workspace run show -id=run-abc123
hcptf workspace run apply -id=run-abc123
-
Sensitive variables
hcptf variable create -org=my-org -workspace=prod \
-key=API_KEY -value=secret -sensitive
-
Check drift before deployment
hcptf workspace run assessmentresult list -org=my-org -name=prod
hcptf workspace run assessmentresult read -id=ar-abc123 -show-drift
hcptf workspace run create -org=my-org -name=prod -refresh-only
Common Flags
| Flag | Alias | Description |
|---|
-organization | -org | Organization name |
-name | -workspace | Workspace name |
-output | | table (default) or json |
-force | | Skip confirmation prompts |
-dry-run | | Validate without making API calls |
-fields | | Comma-separated output field filter |
-json-input | | JSON payload (inline, @file, -) |
Getting Help
hcptf --help
hcptf registry --help
hcptf stack --help
hcptf workspace create --help
hcptf registry module list --help
Error Handling
When commands fail:
- Check authentication: Ensure
TFE_TOKEN is set or run hcptf login
- Verify organization: Confirm you have access to the org
- Check resource names: Workspaces and runs must exist
- Review permissions: Ensure your token has required permissions
Examples
Complete Workspace Setup
hcptf workspace create -org=my-org -name=api-service \
-vcs-repo=owner/repo \
-vcs-branch=main \
-working-directory=terraform/
hcptf variable create -org=my-org -workspace=api-service \
-key=environment -value=staging
hcptf variable create -org=my-org -workspace=api-service \
-key=AWS_ACCESS_KEY_ID -value=$AWS_KEY -category=env -sensitive
hcptf notification create -org=my-org -workspace=api-service \
-name=slack-alerts \
-destination-type=slack \
-url=$SLACK_WEBHOOK \
-triggers=run:completed,run:errored
State Management
hcptf state list -org=my-org -workspace=production
hcptf state outputs -org=my-org -workspace=production
hcptf state read -org=my-org -workspace=production -output=json > state.json
Policy Management
hcptf policy create -org=my-org \
-name=cost-limit \
-enforce-mode=hard-mandatory \
-policy-file=policies/cost.sentinel
hcptf policyset create -org=my-org \
-name=production-policies \
-global=true
hcptf policyset add-policy -org=my-org \
-policyset=production-policies \
-policy=cost-limit
Troubleshooting
Authentication Issues
hcptf account show
hcptf logout
hcptf login
Finding Resource IDs
hcptf workspace read -org=my-org -workspace=staging -output=json | \
jq -r '.data.id'
hcptf workspace run list -org=my-org -name=staging -output=json | \
jq -r '.data[0].id'
Debugging
hcptf workspace run show -id=run-abc123 -output=json | jq .
hcptf workspace run assessmentresult read -id=ar-abc123 -show-drift -summary-only
Reference
- Authentication: See
hcptf login --help
- Configuration:
~/.hcptfrc (HCL format)
- Documentation: README.md in repository
- API Coverage: 100+ commands across 50+ resource types
Notes
- All commands support
-help flag for detailed usage
- Hierarchical structure (registry, stack) is the current standard
- Legacy flat commands have been removed in favor of hierarchical
- URL-style navigation works alongside traditional commands