Skip to content

Commit

Permalink
Adding Installing and Cleanup scripts for remote bash execution for T…
Browse files Browse the repository at this point in the history
…erraform Infra and Base Pattern (#269)

Adding Installing and Cleanup scripts for remote bash execution
  • Loading branch information
elamaran11 authored Apr 26, 2024
1 parent 995505d commit cc82136
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/existing-cluster-with-base-and-infra/cleanup.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions examples/existing-cluster-with-base-and-infra/install.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cc82136

Please sign in to comment.