9. Destroy the infrastructure (done on a per‐lab basis) - AndyGreenPhD/ksu_labs GitHub Wiki

Now that you have completed your lab assignment, you will need to destroy your Terraform infrastructure. NOTE: Failure to do this may result in you accruing charges on your AWS account, so it is important to make sure you do this every time!

This section is written for both Windows and Mac using a single set of instructions.

For Windows users, "terminal" means Command Prompt. The use of $HOMEDIR means your home directory.

Tutorial video can be viewed here

  1. Open a terminal and navigate to the $HOMEDIR\ksu_labs-main\lab root directory of the module. The lab root directory will vary based on class. For example, the lab root directory for ISA and CYBR 3210 is 3210_labs. So, your root directory would be $HOMEDIR\ksu_labs-main\3210_labs
  2. Type terraform state list to get a list of all current AWS assets running under Terraform. You can identify them by the .aws_ text listed in the assets, such as aws_instance, aws_key_pair, or aws_security_group. Take note of these assets to ensure they are destroyed in the following steps.
  3. Type terraform destroy to begin the teardown process.
  4. After a period of time, Terraform will show you a preview of the changes that Terraform will make. Review the changes to make sure that Terraform is going to destroy everything you built for the lab. Be sure that all of the AWS-related assets, as described above, are being destroyed.
  5. Review the changes and type yes when prompted to confirm the changes.
  6. Wait for Terraform to destroy the instances and release any associated resources. You should see the output as each of the AWS-related assets being destroyed
  7. Type exit to close the terminal.