From 260910695f02b1469fed84c6d917cb12815ad80f Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Thu, 25 Apr 2024 18:08:54 -0400 Subject: [PATCH] Adding Installing and Cleanup scripts for remote bash execution --- .../cleanup.sh | 31 ++++++++++++++++++ .../install.sh | 32 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 examples/existing-cluster-with-base-and-infra/cleanup.sh create mode 100755 examples/existing-cluster-with-base-and-infra/install.sh diff --git a/examples/existing-cluster-with-base-and-infra/cleanup.sh b/examples/existing-cluster-with-base-and-infra/cleanup.sh new file mode 100755 index 00000000..713b7b9f --- /dev/null +++ b/examples/existing-cluster-with-base-and-infra/cleanup.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -o errexit +set -o pipefail + +read -p "Enter the region: " region +export AWS_DEFAULT_REGION=$region + +targets=( +"module.eks_monitoring" +) + +for target in "${targets[@]}" +do + terraform destroy -target="$target" -auto-approve + destroy_output=$(terraform destroy -target="$target" -auto-approve 2>&1) + if [[ $? -eq 0 && $destroy_output == *"Destroy complete!"* ]]; then + echo "SUCCESS: Terraform destroy of $target completed successfully" + else + echo "FAILED: Terraform destroy of $target failed" + exit 1 + fi +done + +terraform destroy -auto-approve +destroy_output=$(terraform destroy -auto-approve 2>&1) +if [[ $? -eq 0 && $destroy_output == *"Destroy complete!"* ]]; then + echo "SUCCESS: Terraform destroy of all targets completed successfully" +else + echo "FAILED: Terraform destroy of all targets failed" + exit 1 +fi \ No newline at end of file diff --git a/examples/existing-cluster-with-base-and-infra/install.sh b/examples/existing-cluster-with-base-and-infra/install.sh new file mode 100755 index 00000000..270289c7 --- /dev/null +++ b/examples/existing-cluster-with-base-and-infra/install.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +echo "Initializing ..." +terraform init || echo "\"terraform init\" failed" + +# List of Terraform modules to apply in sequence +targets=( + "module.eks_monitoring" +) + +# Apply modules in sequence +for target in "${targets[@]}" +do + echo "Applying module $target..." + apply_output=$(terraform apply -target="$target" -auto-approve 2>&1 | tee /dev/tty) + if [[ ${PIPESTATUS[0]} -eq 0 && $apply_output == *"Apply complete"* ]]; then + echo "SUCCESS: Terraform apply of $target completed successfully" + else + echo "FAILED: Terraform apply of $target failed" + exit 1 + fi +done + +# Final apply to catch any remaining resources +echo "Applying remaining resources..." +apply_output=$(terraform apply -auto-approve 2>&1 | tee /dev/tty) +if [[ ${PIPESTATUS[0]} -eq 0 && $apply_output == *"Apply complete"* ]]; then + echo "SUCCESS: Terraform apply of all modules completed successfully" +else + echo "FAILED: Terraform apply of all modules failed" + exit 1 +fi \ No newline at end of file