-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautostack_setup.sh
More file actions
126 lines (111 loc) · 4.33 KB
/
Copy pathautostack_setup.sh
File metadata and controls
126 lines (111 loc) · 4.33 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
set -euo pipefail
# Function to display ASCII art
ascii_art() {
echo " █████╗ ██╗ ██╗████████╗ ██████╗ ███████╗████████╗ █████╗ ██████╗██╗ ██╗"
echo "██╔══██╗██║ ██║╚══██╔══╝██╔═══██╗██╔════╝╚══██╔══╝██╔══██╗██╔════╝██║ ██╔╝"
echo "███████║██║ ██║ ██║ ██║ ██║███████╗ ██║ ███████║██║ █████╔╝ "
echo "██╔══██║██║ ██║ ██║ ██║ ██║╚════██║ ██║ ██╔══██║██║ ██╔═██╗ "
echo "██║ ██║╚██████╔╝ ██║ ╚██████╔╝███████║ ██║ ██║ ██║╚██████╗██║ ██╗"
echo "╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝"
echo "=========================================="
echo "Welcome to the Deployment Setup!"
echo "----------------------------------------------"
echo "This script will guide you through setting up"
echo "your server with Terraform and security features."
echo "----------------------------------------------"
echo "Ready? Let's get started! 🚀"
echo "=========================================="
}
# Function to log messages with timestamp
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
# Function to initialize Terraform
initialize_terraform() {
log "Initializing Terraform..."
if ! terraform init -input=false; then
log "Terraform initialization failed. Please check your configuration."
exit 1
fi
}
# Function to run Terraform plan
plan_terraform() {
log "Running Terraform plan..."
if ! terraform plan -input=false; then
log "Terraform plan failed. Please check your configuration."
exit 1
fi
}
# Function to apply Terraform changes
apply_terraform() {
log "Applying Terraform changes..."
if ! terraform apply -auto-approve -input=false; then
log "Terraform apply failed. Please check your configuration."
exit 1
fi
}
# Prompt user for setup profile choice (minimal, standard, hardcore)
select_setup_profile() {
log "Select the setup profile:"
echo "1) Minimal"
echo "2) Standard"
echo "3) Hardcore"
read -r profile_choice
case $profile_choice in
1)
export TF_VAR_setup_profile="minimal"
log "Setup profile set to Minimal."
;;
2)
export TF_VAR_setup_profile="standard"
log "Setup profile set to Standard."
;;
3)
export TF_VAR_setup_profile="hardcore"
log "Setup profile set to Hardcore."
;;
*)
log "Invalid selection. Exiting."
exit 1
;;
esac
}
# Check if Terraform is installed
check_terraform() {
if ! command -v terraform &> /dev/null; then
log "ERROR: Terraform is not installed. Please install Terraform before running this script."
exit 1
fi
}
# Validate Terraform configuration
validate_terraform() {
log "Validating Terraform configuration..."
terraform validate || { log "Terraform validation failed."; exit 1; }
}
# Format Terraform configuration files
format_terraform() {
log "Formatting Terraform configuration files..."
terraform fmt -recursive
}
# Main function to orchestrate the setup
main() {
ascii_art
log "Starting Autostack setup script for Terraform..."
check_terraform
select_setup_profile
initialize_terraform
validate_terraform
format_terraform
plan_terraform
log "Do you want to apply the Terraform changes? (y/n)"
read -r apply_choice
if [[ $apply_choice == "y" ]]; then
apply_terraform
else
log "Skipping apply phase. You can apply changes later using 'terraform apply'."
fi
log "Autostack setup complete for Terraform."
}
# Run the main function
main