atmos terraform workdir clean
Use this command to remove workdirs from your project. This is useful for freeing disk space, forcing regeneration of workdirs, or cleaning up after components are removed.
Usage
atmos terraform workdir clean [component] [flags]
Arguments
component- Optional. The name of the Terraform component whose workdir you want to clean. If not specified, use
--allto clean all workdirs.
Flags
-s, --stack- The stack name for the component. Required when cleaning a specific component.
--all- Clean all workdirs in the project. Cannot be used with a specific component.
--force- Skip confirmation prompt.
--dry-run- Show what would be cleaned without actually removing anything.
Examples
Clean a Specific Workdir
# Clean the workdir for vpc component in dev stack
atmos terraform workdir clean vpc --stack dev
Output:
Cleaned workdir: .workdir/terraform/dev-vpc
Clean All Workdirs
# Clean all workdirs in the project
atmos terraform workdir clean --all
Output:
This will remove all workdirs in .workdir/terraform/
Continue? [y/N]: y
Cleaned 5 workdirs:
- dev-vpc
- staging-vpc
- prod-vpc
- dev-s3-bucket
- staging-s3-bucket
Dry Run
# See what would be cleaned without removing
atmos terraform workdir clean --all --dry-run
Output:
Would clean 5 workdirs:
- .workdir/terraform/dev-vpc
- .workdir/terraform/staging-vpc
- .workdir/terraform/prod-vpc
- .workdir/terraform/dev-s3-bucket
- .workdir/terraform/staging-s3-bucket
Force Clean Without Confirmation
# Clean all workdirs without confirmation prompt
atmos terraform workdir clean --all --force
When to Clean Workdirs
Consider cleaning workdirs in these scenarios:
-
Disk Space - Workdirs can accumulate significant disk space over time, especially with large
.terraformdirectories containing provider binaries. -
Force Regeneration - If you suspect workdir contents are stale or corrupted, cleaning forces a fresh copy on the next
terraform init. -
Component Removal - After removing a component from your configuration, clean its workdir to remove orphaned files.
-
Troubleshooting - When debugging Terraform issues, starting with a clean workdir can help isolate problems.
Workdir Regeneration
After cleaning a workdir, it will be automatically recreated the next time you run a Terraform command:
# Clean the workdir
atmos terraform workdir clean vpc --stack dev
# Workdir is recreated on next init
atmos terraform init vpc --stack dev
Safety Considerations
Cleaning a workdir removes all Terraform state-related files in that directory, including:
- Downloaded provider plugins (
.terraform/) - Lock files (
.terraform.lock.hcl) - Generated varfiles and planfiles
This does not affect your remote Terraform state (e.g., S3 backend). However, you will need to re-run terraform init to download providers again.
Related Commands
atmos terraform workdir list- List all workdirsatmos terraform workdir show- Show workdir detailsatmos terraform workdir describe- Output workdir as stack manifestatmos terraform clean- Clean Terraform files from component directoriesatmos terraform init- Initialize and recreate workdir