不要リソースの削除

ハンズオンが終わったら、課金を避けるため、作成したリソースを削除します。

terraform destroy

確認プロンプトが表示されたら、yesと入力して実行します。

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

削除が完了すると、以下のように表示されます。

Destroy complete! Resources: 6 destroyed.
💡 ポイント
terraform destroyは、Terraformで管理しているすべてのリソースを削除します。Terraformはリソース間の依存関係を理解しているため、正しい順序(EC2 → サブネット → VPCなど)で削除を行います。

1. 作業フォルダの削除(任意)

プロジェクトフォルダを削除する場合は、以下のコマンドを実行します。

rm -rf ~/terraform-aws-basic