| name | version-upgrades |
| description | Upgrade Terraform, provider, module, and policy versions in HCP Terraform workspaces. Use when upgrading workspace Terraform version, updating provider versions for security patches or new features, upgrading modules or policy sets, or planning organization-wide version updates. |
Version Upgrade Skill
Overview
This skill helps upgrade Terraform, provider, module, and policy versions in HCP Terraform workspaces. Keeping versions current improves security, performance, and access to new features.
Prerequisites
- Authenticated with
hcptf CLI
- Write access to target workspace
- VCS access if updating provider/module/policy versions in code
Core Concepts
Version Types:
- Terraform Version: The Terraform CLI version used to run plans/applies
- Provider Versions: API plugins defined in
required_providers block
- Module Versions: Reusable module versions called with
source argument
- Policy Versions: Sentinel/OPA policy sets for compliance and governance
Upgrade Approaches:
-
Terraform Version (Simple - Workspace Setting):
- One command:
hcptf workspace update -terraform-version=latest
- No code changes needed
- Takes effect on next run
-
Provider/Module/Policy Versions (Complex - Requires Code Changes):
- Get git repo info from workspace
- Clone repository
- Edit Terraform files (versions.tf, main.tf, sentinel.hcl, etc.)
- Update version constraints
- Commit and push changes
- VCS triggers new run automatically
Workflow
1. Check Current Versions
For a specific workspace:
hcptf <org> <workspace>
hcptf explorer query -org=<org> -type=workspaces \
-filter="workspace-name:<workspace>" \
-fields=workspace-name,workspace-terraform-version,providers,modules
For all workspaces in org:
hcptf explorer query -org=<org> -type=tf_versions \
-sort=version
hcptf explorer query -org=<org> -type=providers \
-sort=-version \
-fields=name,version,workspace-count,workspaces
hcptf explorer query -org=<org> -type=modules \
-sort=-version \
-fields=name,version,workspace-count,workspaces
2. Find Latest Versions
Terraform versions:
Public provider versions:
-
Provider registry page: https://registry.terraform.io/providers/<namespace>/<name>/latest
-
Documentation includes changelog, upgrade guides, and version history
-
In use across org: hcptf explorer query -org=<org> -type=providers
-
CLI commands:
hcptf publicregistry provider -name=hashicorp/aws
hcptf publicregistry provider versions -name=hashicorp/aws
Private provider versions:
hcptf registry provider list -organization=<org>
hcptf registry provider read -organization=<org> -name=<provider>
hcptf registry provider version read -organization=<org> \
-name=<provider> -version=<version>
Public module versions:
-
Module registry page: https://registry.terraform.io/modules/<namespace>/<name>/<system>
-
Shows available versions, inputs/outputs, and usage examples
-
In use across org: hcptf explorer query -org=<org> -type=modules
-
CLI commands:
hcptf publicregistry module -name=terraform-aws-modules/vpc/aws
hcptf publicregistry module -name=terraform-aws-modules/s3-bucket/aws
Private module versions:
hcptf registry module list -organization=<org>
hcptf registry module read -organization=<org> -namespace=<org> -name=<module>
Public policy versions:
-
Policy registry page: https://registry.terraform.io/policies/<namespace>/<name>
-
Shows available versions, included policies, and modules
-
CLI commands:
hcptf publicregistry policy list
hcptf publicregistry policy -name=hashicorp/CIS-Policy-Set-for-AWS-Terraform
hcptf publicregistry policy -name=hashicorp/CIS-Policy-Set-for-Azure-Terraform -version=1.0.0
hcptf publicregistry policy -name=hashicorp/gcp-networking-terraform
Private policy versions:
hcptf policyset list -organization=<org>
hcptf policyset read -organization=<org> -id=<policy-set-id>
3. Upgrade Terraform Version (Workspace Setting)
hcptf workspace update -org=<org> -name=<workspace> \
-terraform-version=1.10.0
hcptf workspace update -org=<org> -name=<workspace> \
-terraform-version=latest
hcptf workspace update -org=<org> -name=<workspace> \
-terraform-version="~>1.10.0"
4. Upgrade Provider/Module/Policy Versions (Code Changes)
Provider, module, and policy versions are defined in code and require updating the Terraform files.
Get code location:
RUN_ID=$(hcptf <org> <workspace> -output=json | jq -r '.CurrentRunID')
hcptf <org> <workspace> runs $RUN_ID configversion
Update provider version in code:
Important: Provider version constraints can come from multiple sources:
- Root-level
required_providers blocks in your workspace code (you can update these directly)
- Module-level
required_providers blocks in consumed modules (you CANNOT update these directly)
If provider versions are declared within a module you're consuming, you must either:
- Update to a newer version of the module that supports the desired provider version
- Check the module's documentation/changelog for supported provider versions
- Fork and modify the module (not recommended for registry modules)
Use terraform providers to see the provider dependency tree and identify where constraints originate.
# In versions.tf or terraform block (ROOT-LEVEL ONLY)
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.28.0" # Updated from 5.69.0
}
}
}
Update module version in code:
# In main.tf or module call
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> 5.10.0" # Updated from 4.0.0
# ...
}
5. Test the Upgrade
Create a test run to verify the upgrade works:
hcptf <org> <workspace> runs create \
-message="Upgrade Terraform to 1.10.0, AWS provider to 6.28.0"
hcptf <org> <workspace> runs list | head -5
hcptf <org> <workspace> runs <run-id> show
If the plan shows issues:
- Check plan output:
hcptf <org> <workspace> runs <run-id> plan
- View logs:
hcptf <org> <workspace> runs <run-id> logs
6. Apply if Successful
hcptf <org> <workspace> runs <run-id> apply
7. Verify
hcptf <org> <workspace>
hcptf explorer query -org=<org> -type=workspaces \
-filter="workspace-name:<workspace>" \
-fields=workspace-name,workspace-terraform-version,providers,modules
Common Scenarios
Scenario 1: Upgrade Terraform Version Only
hcptf my-org my-workspace
hcptf workspace update -org=my-org -name=my-workspace \
-terraform-version=latest
hcptf my-org my-workspace runs create -message="Test Terraform 1.10 upgrade"
hcptf my-org my-workspace runs <run-id> apply
Scenario 2: Upgrade AWS Provider (Major Version)
Important: Provider versions are in code, not workspace settings. You MUST clone the repo and edit files.
hcptf explorer query -org=my-org -type=workspaces \
-filter="workspace-name:my-workspace" \
-fields=workspace-name,providers
RUN_ID=$(hcptf my-org my-workspace -output=json | jq -r '.CurrentRunID')
hcptf my-org my-workspace runs $RUN_ID configversion
git clone https://github.com/thrashr888/my-infra
cd my-infra
git checkout main
git add versions.tf
git commit -m "Upgrade AWS provider from v5 to v6"
git push origin main
hcptf my-org my-workspace runs list | head -5
RUN_ID=$(hcptf my-org my-workspace -output=json | jq -r '.CurrentRunID')
hcptf my-org my-workspace runs $RUN_ID show
hcptf my-org my-workspace runs $RUN_ID apply
hcptf explorer query -org=my-org -type=workspaces \
-filter="workspace-name:my-workspace" \
-fields=workspace-name,providers
Scenario 3: Upgrade Multiple Workspaces
hcptf explorer query -org=my-org -type=tf_versions \
-fields=version,workspace-count,workspaces
for ws in workspace1 workspace2 workspace3; do
echo "Upgrading $ws..."
hcptf workspace update -org=my-org -name=$ws -terraform-version=1.10.0
done
for ws in workspace1 workspace2 workspace3; do
echo "Testing $ws..."
hcptf my-org $ws runs create -message="Test Terraform 1.10 upgrade"
done
Scenario 4: Upgrade Module Versions
Important: Module versions are in code. You MUST clone the repo and edit the module source blocks.
hcptf explorer query -org=my-org -type=modules \
-fields=name,version,workspaces
RUN_ID=$(hcptf my-org cool-website -output=json | jq -r '.CurrentRunID')
hcptf my-org cool-website runs $RUN_ID configversion
git clone https://github.com/thrashr888/cool-website
cd cool-website
git checkout main
git add main.tf
git commit -m "Upgrade s3-bucket module from v4 to v5.10"
git push origin main
hcptf my-org cool-website runs list | head -5
hcptf explorer query -org=my-org -type=modules \
-fields=name,version,workspaces | grep cool-website
Scenario 5: Upgrade Policy Versions
Important: Policy versions are managed in VCS-backed policy sets via sentinel.hcl configuration.
hcptf policyset list -organization=my-org
hcptf publicregistry policy list | grep CIS
hcptf publicregistry policy -name=hashicorp/CIS-Policy-Set-for-AWS-Terraform
hcptf policyset read -organization=my-org -id=<policy-set-id>
git clone <policy-repo-url>
cd policy-repo
git add sentinel.hcl
git commit -m "Upgrade CIS AWS policy set from v1.0.0 to v1.0.1"
git push origin main
hcptf policyset read -organization=my-org -id=<policy-set-id>
Version Compatibility
Terraform version constraints:
1.9.0 - Exact version
~> 1.9.0 - Pessimistic constraint (1.9.x only)
~> 1.9 - Allow 1.x (1.9.0, 1.10.0, etc.)
>= 1.9.0 - Minimum version
latest - Always use newest available
Provider version constraints:
Follow same syntax. Use pessimistic constraints to avoid breaking changes:
~> 5.69.0 - Allow 5.69.x patches only
~> 5.0 - Allow 5.x minor/patch updates
Upgrade Considerations
Before upgrading:
- Review changelogs for breaking changes
- Check workspace health (no drift, checks passing)
- Have rollback plan ready
- Test in non-production workspace first
Terraform version upgrades:
- Usually safe for patch versions (1.9.6 → 1.9.7)
- Minor versions may have deprecations (1.9.x → 1.10.x)
- Major versions have breaking changes (review upgrade guide)
Provider version upgrades:
- Patch versions are safe (5.69.0 → 5.69.1)
- Minor versions may add deprecations (5.69.x → 5.70.x)
- Major versions have breaking changes (5.x → 6.x)
- Always review provider upgrade guide
Module version upgrades:
- Depends on module's versioning practice
- Check module changelog and README
- Test for interface changes (new required variables, removed outputs)
Policy version upgrades:
- Review policy changelog for new/removed checks
- Check if new policies require additional parameters
- Test in non-production workspace first
- Consider impact on existing runs (advisory vs mandatory enforcement)
- Verify policy modules are compatible
Rollback
If upgrade fails:
hcptf workspace update -org=<org> -name=<workspace> \
-terraform-version=1.9.6
Related Commands
hcptf explorer query - Find versions in use across org
hcptf workspace read - View workspace Terraform version
hcptf workspace update - Update workspace Terraform version
hcptf configversion read - Get VCS info to find code
hcptf run create - Test upgraded configuration
hcptf run show - Monitor upgrade run
hcptf publicregistry provider - Get public provider info and latest version
hcptf publicregistry provider versions - List all available provider versions
hcptf publicregistry module - Get public module info and latest version
hcptf publicregistry policy - Get public policy info and latest version
hcptf publicregistry policy list - List all available public policies
hcptf registry module read - Check private module versions
hcptf policyset list - List policy sets in organization
hcptf policyset read - View policy set details and VCS info
Tips
- Upgrade incrementally: Don't jump multiple major versions at once
- Test first: Always run plan before apply
- Document: Include clear messages in runs explaining what's being upgraded
- Monitor: Watch run logs for deprecation warnings
- Coordinate: For major provider upgrades, update all workspaces using that provider
- Use constraints: Prefer
~> constraints over exact versions for easier patch updates
- Stage upgrades: Test in dev/staging before production
- Policy upgrades: Review new policy checks and set to advisory mode first before enforcing
- Use CLI tools: Leverage
publicregistry commands to quickly check latest versions without leaving terminal