Link Search Menu Expand Document

Run this Script to uninstall Elastio

Use this script to remove the Elastio CloudFormation stack, all Cloud Connectors and Vaults. Save the following script to a .yaml file on your machine, make it executable and run.

Note: This clean up script will fully work only in environments where the CLI version matches the artifacts version and the deploy is not misconfigured. This restriction is going away soon.

This script will delete all resources including vaults, Cloud Connectors and the Cloud Formation stack.

Important: The latest AWS CLI v.2 should be installed on the machine for the script to work properly, as well as the Elastio CLI. The AWS CLI should be configured to have access to the account you are attempting to clean up.

#!/bin/bash
set -ex

str=$(aws --version)
major_v=$(echo $str | cut -d' ' -f1 | cut -d'/' -f2 | cut -d'.' -f1)

 if [ $major_v -eq 2 ]; then
     echo "AWS CLI2 installed"
     elastio -V
     if [ $? -eq 0 ]; then
         echo "Elastio CLI installed"
         start_region=$(aws configure get region)
         regions=("us-east-1" "us-east-2" "us-west-2" "eu-central-1" "ap-southeast-2")
 
         #get and delete all vaults
         for reg in "${regions[@]}"
         do
             aws configure set default.region $reg
             aws configure set region $reg  
             if elastio vault list --output-format json --aws-region $reg;
             then
                 echo "$reg have red stack"
                 for v in $(elastio vault list --output-format json --aws-region $reg | grep -Po '"vault_id": *\K"[^"]*"' | tr -d '"')
                 do
                     echo "$v vault will be deleted from $reg aws-region"
                     # echo $v 
                     vaults+=("$v")
                     elastio vault delete $v --aws-region $reg
                 done
 
                 elastio stack destroy --aws-region $reg
 
                 for value in "${vaults[@]}"
                 do
                     aws kms delete-alias --alias-name alias/elastio-vault-$value-key || true
                 done
 
                 aws ecs describe-capacity-providers --query "capacityProviders[*].name" | \
                 grep elastio-vault | \
                 sed 's/"//'g | \
                 sed 's/,//' | \
                 sed 's/ //'g | \
                 xargs -t -n1 aws ecs delete-capacity-provider --capacity-provider || true
 
                 aws kms delete-alias --alias-name alias/elastio-vault-default-key || true
 
                 aws kms delete-alias --alias-name alias/elastio-provisioner-auth-signing-key || true
 
                 filter="elastio-"
 
                 aws batch describe-job-definitions --status 'ACTIVE' | \
                     grep "jobDefinitionArn" | \
                     grep $filter | \
                     awk '{ print $2 }' | \
                     tr -d \", | \
                     xargs -t -n1 -I '{}' aws batch deregister-job-definition --job-definition '{}'
             else
                 echo "$reg doesn't have red stack"
 
                 aws ecs describe-capacity-providers --query "capacityProviders[*].name" | \
                 grep elastio-vault | \
                 sed 's/"//'g | \
                 sed 's/,//' | \
                 sed 's/ //'g | \
                 xargs -t -n1 aws ecs delete-capacity-provider --capacity-provider || true
 
                 aws kms delete-alias --alias-name alias/elastio-vault-default-key || true
 
                 aws kms delete-alias --alias-name alias/elastio-provisioner-auth-signing-key || true
 
                 filter="elastio-"
 
                 aws batch describe-job-definitions --status 'ACTIVE' | \
                     grep "jobDefinitionArn" | \
                     grep $filter | \
                     awk '{ print $2 }' | \
                     tr -d \", | \
                     xargs -t -n1 -I '{}' aws batch deregister-job-definition --job-definition '{}'
             fi
         done
 
         for reg in "${regions[@]}"
         do
             aws configure set default.region $reg
             aws configure set region $reg
             echo "CFN will be deleted for $reg aws-region"
             aws cloudformation delete-stack --stack-name elastio-account-level-stack
             s3s=$(aws s3 ls --human-readable)
             echo "$s3s" > temp.txt
             filename=temp.txt
             bucket_name=elastio-report
             
             while read line; do
             # reading each line
             formated_line=$(echo $line | cut -d' ' -f3)
                 if [[ "$formated_line" == *$bucket_name* ]]; then
                     aws s3 rb s3://$formated_line --force
                 fi
             done < $filename
             rm temp.txt
         done
         aws configure set default.region $start_region
         aws configure set region $start_region
	 aws cur --region us-east-1 delete-report-definition --report-name "elastio-report"
     else
         echo "Elastio CLI not installed"
     fi
 else
     echo "AWS CLI not installed. Install AWS CLI v.2 to proceed"
 fi