Skip to main content

2.5.5 Destroying Environments

Youtube ๐Ÿ“บ

Now that our demonstration for the multi-environment workflow is completed, let's destroy the EC2s that were created as its not something we need for the course ahead. We can do it be using the admin credentials configured earlier in our AWS Setup section.

โ†ฉ๏ธ Rebasing Gitโ€‹

  • First thing we need to do is to rebase our code in the Cloud Desktop to the latest in the main branch.
cd ~/playground
git checkout main
git pull

โŒ Destroy Dev environmentโ€‹

  • Open the CLI on the Cloud Desktop and fire the following commands to initalise the dev environment state locally and then destroy the dev environment
cd ~/playground/infra
export AWS_PROFILE=admin
terraform init -backend-config=dev.hcl

cd ~/playground/infra
export AWS_PROFILE=admin
terraform destroy -var-file=dev.tfvars --auto-approve

โŒ Destroy Prod Environmentโ€‹

Similarly, fire the below commands to destroy Prod environment

cd ~/playground/infra
export AWS_PROFILE=admin
terraform init -backend-config=prod.hcl -reconfigure
terraform destroy -var-file=prod.tfvars --auto-approve
End of Chapter 2

That completes the Chapter 2, before you move to Chapter 3