Skip to main content

atmos terraform clean

Use this command to clean up Terraform files for an Atmos component in a stack. This removes .terraform folder, .terraform.lock.hcl file, and Atmos-generated varfiles and planfiles.

atmos terraform clean --help

Usage​

Execute the terraform clean command like this:

atmos terraform clean <component> -s <stack> [--skip-lock-file] [--everything] [--force]
warning

The clean command, by default, deletes all Terraform-related files, including local state files, but will prompt for confirmation before proceeding. Using the --force flag skips the confirmation prompt and executes the deletion immediately. Use these flags with extreme caution as they can lead to irreversible data loss.

tip

Run atmos terraform clean --help to see all the available options

Configuration​

Configure default behavior for terraform clean in your atmos.yaml:

components:
terraform:
# Auto-generate backend configuration
auto_generate_backend_file: true

The Terraform data directory location can be controlled via environment variable:

# Set custom Terraform data directory (defaults to .terraform)
export TF_DATA_DIR="/tmp/.terraform"

Examples​

# Delete all Terraform-related files for all components (with confirmation)
atmos terraform clean
# Force delete all Terraform-related files for all components (no confirmation)
atmos terraform clean --force
atmos terraform clean top-level-component1 -s tenant1-ue2-dev
atmos terraform clean infra/vpc -s tenant1-ue2-staging
atmos terraform clean infra/vpc -s tenant1-ue2-staging --skip-lock-file
atmos terraform clean test/test-component -s tenant1-ue2-dev
atmos terraform clean test/test-component-override-2 -s tenant2-ue2-prod
atmos terraform clean test/test-component-override-3 -s tenant1-ue2-dev

Arguments​

component (required)

Atmos terraform component.

Flags​

--stack (alias -s) (required)

Atmos stack.

--dry-run (optional)

Dry run.

atmos terraform clean <component> -s <stack> --dry-run=true
--skip-lock-file (optional)

Skip deleting the .terraform.lock.hcl file.