-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathdestroy.sh
More file actions
executable file
·105 lines (85 loc) · 3.17 KB
/
Copy pathdestroy.sh
File metadata and controls
executable file
·105 lines (85 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Exit on any error
set -e
# Colors for better visual feedback
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check if .deployment.config exists
if [ ! -f ".deployment.config" ]; then
echo -e "${RED}Error: .deployment.config file not found.${NC}"
echo -e "${BLUE}This file is required as it contains the deployment configuration.${NC}"
exit 1
fi
# Load deployment config
source .deployment.config
# Verify required variables
required_vars=("USERNAME" "EMAIL" "GIVEN_NAME" "FAMILY_NAME" "REGION")
missing_vars=0
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
echo -e "${RED}Error: ${var} is missing in .deployment.config${NC}"
missing_vars=1
fi
done
if [ $missing_vars -eq 1 ]; then
echo -e "${RED}Required variables are missing in .deployment.config${NC}"
exit 1
fi
# Confirmation prompt
echo -e "${RED}Warning: This will destroy all infrastructure created by Terraform.${NC}"
echo -e "\n${BLUE}Configuration that will be used:${NC}"
echo -e "Username: ${GREEN}$USERNAME${NC}"
echo -e "Email: ${GREEN}$EMAIL${NC}"
echo -e "Given Name: ${GREEN}$GIVEN_NAME${NC}"
echo -e "Family Name: ${GREEN}$FAMILY_NAME${NC}"
echo -e "Region: ${GREEN}$REGION${NC}"
while true; do
echo -e "\n${RED}Are you sure you want to proceed with destruction? (yes/no)${NC}"
read -r answer
case $answer in
yes ) break;;
no ) echo -e "${BLUE}Destruction cancelled.${NC}"; exit 0;;
* ) echo -e "${RED}Please answer 'yes' or 'no'${NC}";;
esac
done
# Change to terraform directory
cd ./infra
# Verify terraform is initialized
if [ ! -d ".terraform" ]; then
echo -e "${BLUE}Initializing Terraform...${NC}"
if ! terraform init; then
echo -e "${RED}Terraform initialization failed. Exiting...${NC}"
exit 1
fi
fi
# Run terraform destroy
echo -e "\n${BLUE}Starting infrastructure destruction...${NC}"
# Build terraform destroy command with required variables
TF_DESTROY_VARS="-var=username=$USERNAME"
TF_DESTROY_VARS="$TF_DESTROY_VARS -var=given_name=$GIVEN_NAME"
TF_DESTROY_VARS="$TF_DESTROY_VARS -var=family_name=$FAMILY_NAME"
TF_DESTROY_VARS="$TF_DESTROY_VARS -var=email=$EMAIL"
TF_DESTROY_VARS="$TF_DESTROY_VARS -var=region=$REGION"
# Add enable_sentry if it exists in config, otherwise use default
if [ -n "$ENABLE_SENTRY" ]; then
TF_DESTROY_VARS="$TF_DESTROY_VARS -var=enable_sentry=$ENABLE_SENTRY"
fi
# Add enable_maestro if it exists in config, otherwise use default
if [ -n "$ENABLE_MAESTRO" ]; then
TF_DESTROY_VARS="$TF_DESTROY_VARS -var=enable_maestro=$ENABLE_MAESTRO"
fi
# Set safe defaults for model provider variables (not needed for destroy but required by Terraform)
TF_DESTROY_VARS="$TF_DESTROY_VARS -var=model_provider=bedrock"
TF_DESTROY_VARS="$TF_DESTROY_VARS -var=openai_api_key=dummy-key-for-destroy"
if ! terraform destroy -auto-approve $TF_DESTROY_VARS; then
echo -e "${RED}Terraform destroy failed. Exiting...${NC}"
exit 1
fi
# Return to root directory
cd ..
# Cleanup local files
echo -e "\n${BLUE}Cleaning up local files...${NC}"
rm -f .env .deployment.config
echo -e "\n${GREEN}Infrastructure successfully destroyed and local files cleaned up.${NC}"