Linux command
terraform-destroy 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Destroy
terraform destroy
Destroy
terraform destroy -auto-approve
Destroy
terraform destroy -target=[resource_type.resource_name]
Preview
terraform plan -destroy
Destroy
terraform destroy -var '[name]=[value]'
Destroy
terraform destroy -var-file=[prod.tfvars]
Destroy
terraform destroy -parallelism=[5]
说明
terraform destroy permanently deletes all infrastructure resources tracked in the current Terraform state file. It is a convenience alias for terraform apply -destroy. The command reads the state file to identify managed resources, validates state against cloud provider APIs, builds a dependency graph to determine the correct reverse destruction order, presents a plan for confirmation, and then deletes resources via provider APIs. After completion, it updates the state file to reflect that the resources no longer exist. It is designed primarily for ephemeral infrastructure in development and testing environments. For production, it should only be used in controlled decommissioning scenarios.
参数
- -auto-approve
- Skip the interactive confirmation prompt
- -target=_RESOURCE_
- Destroy only the specified resource and its dependencies. Can be specified multiple times.
- -var '_NAME_=_VALUE_'
- Set an input variable value. Can be specified multiple times.
- -var-file=_PATH_
- Load variable values from a file
- -lock=_BOOL_
- Control whether Terraform locks the state file. Default: true.
- -lock-timeout=_DURATION_
- How long to wait to acquire the state lock. Example: 20s.
- -parallelism=_N_
- Limit concurrent resource operations. Default: 10.
- -refresh=_BOOL_
- Whether to refresh state before planning. Default: true.
- -state=_PATH_
- Path to the state file. Default: terraform.tfstate.
- -no-color
- Disable color output
FAQ
What is the terraform-destroy command used for?
terraform destroy permanently deletes all infrastructure resources tracked in the current Terraform state file. It is a convenience alias for terraform apply -destroy. The command reads the state file to identify managed resources, validates state against cloud provider APIs, builds a dependency graph to determine the correct reverse destruction order, presents a plan for confirmation, and then deletes resources via provider APIs. After completion, it updates the state file to reflect that the resources no longer exist. It is designed primarily for ephemeral infrastructure in development and testing environments. For production, it should only be used in controlled decommissioning scenarios.
How do I run a basic terraform-destroy example?
Run `terraform destroy` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -auto-approve do in terraform-destroy?
Skip the interactive confirmation prompt