Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terraform cleanup #675

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions terraform/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cleanupDirs = ecs ec2 eks

.PHONY: fmt
fmt:
Expand All @@ -22,5 +23,10 @@ postBatchClean:
.PHONY: checkCacheHits
checkCacheHits:
cat test-case-batch | xargs -L1 -P1 ./checkCacheHit.sh

.PHONY: terraformCleanup
terraformCleanup: test-case-batch
cat test-case-batch | xargs -L1 ./executeTerraformCleanup.sh



67 changes: 67 additions & 0 deletions terraform/executeTerraformCleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
##########################################
# This script is used to destroy any
# leftover resources in the case where
# a GitHub actions workflow is cancelled.
# There is a chance that this will fail due to
# the eks fargate and adot operator tests requiring
# options to pass in. This is a best effort to clean up
# as many resources as possible though and any type
# of cleanup is better than cancelling with no cleanup.
#
#
# Inputs
# $1: aws_service
# $2: testcase
# $3: ECS/EC2 only - ami/ecs launch type
# $3: For EKS-arm64 we expect region|clustername|amp_endoint

##########################################

set -e
set -x

echo "Test Case Args: $@"


opts=""
if [[ -f ./testcases/$2/parameters.tfvars ]] ; then
opts="-var-file=../testcases/$2/parameters.tfvars" ;
fi

APPLY_EXIT=0
TEST_FOLDER=""
service="$1"
export AWS_REGION=us-west-2
case "$service" in
"EC2") TEST_FOLDER="./ec2/";
export TF_VAR_testing_ami=$3;
;;
"EKS") TEST_FOLDER="./eks/";
;;
"EKS_ARM64") TEST_FOLDER="./eks/"
arm_64_region=$(echo $3 | cut -d \| -f 1);
export AWS_REGION=${arm_64_region}
export TF_VAR_region=${arm_64_region}
;;
"EKS_FARGATE") TEST_FOLDER="./eks/";
;;
"EKS_ADOT_OPERATOR") TEST_FOLDER="./eks/";
;;
"ECS") TEST_FOLDER="./ecs/";
export TF_VAR_ecs_launch_type=$3;
;;
*)
echo "service ${service} is not valid";
exit 1;
;;
esac


case "$service" in
"EKS_FARGATE" | "EKS_ADOT_OPERATOR") terraform destroy --auto-approve $opts;
;;
*)
terraform destroy --auto-approve;
;;
esac