Loading

Quipoin Menu

Learn • Practice • Grow

terraform / Apply and Destroy
tutorial

Apply and Destroy

After writing your configuration, you need to apply it to create resources and later destroy them. This chapter covers the apply and destroy commands in detail, along with best practices.

terraform apply

The apply command creates or updates resources to match your configuration. By default, it shows a plan and asks for confirmation.
terraform apply
To auto‑approve (use with caution):
terraform apply -auto-approve
Apply a saved plan:
terraform plan -out=tfplan
terraform apply tfplan

terraform destroy

The destroy command removes all resources defined in your configuration.
terraform destroy
To auto‑approve:
terraform destroy -auto-approve
Destroy specific resources (using target):
terraform destroy -target=aws_instance.web

Applying with Variables

Pass variables via files or CLI:
terraform apply -var-file="prod.tfvars"
terraform apply -var="instance_type=t3.micro"

State Refresh

Before planning, Terraform refreshes state. You can manually refresh:
terraform refresh

Best Practices

  • Always review the plan before applying.
  • Use remote state and locking for teams.
  • Destroy resources in a controlled order (Terraform does this automatically).
  • Run terraform plan in CI/CD to catch changes before merge.
  • Use workspaces or variable files for different environments.


Two Minute Drill
  • terraform apply creates/updates resources.
  • terraform destroy removes all resources.
  • Use -auto-approve to skip confirmation (careful!).
  • Pass variables with -var-file or -var.
  • Always review the plan before applying in production.

Need more clarification?

Drop us an email at career@quipoinfotech.com