-
Notifications
You must be signed in to change notification settings - Fork 1
/
talos_deploy.sh
executable file
·121 lines (101 loc) · 2.9 KB
/
talos_deploy.sh
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
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print error messages
error() {
echo -e "${RED}ERROR: $1${NC}" >&2
}
# Function to print success messages
success() {
echo -e "${GREEN}SUCCESS: $1${NC}"
}
# Function to print info messages
info() {
echo -e "${YELLOW}INFO: $1${NC}"
}
# Print start message
echo -e "${GREEN}=======================================${NC}"
echo -e "${GREEN}Starting Deployment of Talos Kubernetes Cluster on Proxmox${NC}"
echo -e "${GREEN}=======================================${NC}"
echo
# Function to check Packer version
check_packer_version() {
if ! command -v packer &> /dev/null; then
error "Packer is not installed or not in PATH"
exit 1
fi
local version=$(packer version | head -n1 | cut -d' ' -f2)
info "Packer version: $version"
}
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Function to validate Packer templates
validate_packer_templates() {
info "Validating Packer templates..."
if packer validate \
-var-file="${SCRIPT_DIR}/packer/local.pkrvars.hcl" \
"${SCRIPT_DIR}/packer/proxmox.pkr.hcl"; then
success "Packer templates are valid"
else
error "Packer template validation failed"
exit 1
fi
}
# Run Packer to build the image
run_packer_build() {
info "Starting Packer build..."
if packer build \
-var-file="${SCRIPT_DIR}/packer/local.pkrvars.hcl" \
-on-error=ask \
"${SCRIPT_DIR}/packer/proxmox.pkr.hcl"; then
success "Packer build completed successfully"
else
error "Packer build failed"
exit 1
fi
}
# Check Packer version
check_packer_version
# Validate Packer templates
validate_packer_templates
# Run Packer build
run_packer_build
# Initialize Terraform
info "Initializing Terraform..."
if terraform -chdir=terraform init; then
success "Terraform initialized successfully"
else
error "Terraform initialization failed"
exit 1
fi
# Validate Terraform configuration
info "Validating Terraform configuration..."
if terraform -chdir=terraform validate; then
success "Terraform configuration is valid"
else
error "Terraform configuration is invalid"
exit 1
fi
# Plan Terraform changes
info "Planning Terraform changes..."
if terraform -chdir=terraform plan -out=tfplan; then
success "Terraform plan created successfully"
else
error "Terraform plan failed"
exit 1
fi
# Apply Terraform changes
info "Applying Terraform changes..."
if terraform -chdir=terraform apply -auto-approve tfplan; then
success "Terraform apply completed successfully"
else
error "Terraform apply failed"
exit 1
fi
# Optional: Show Terraform output
info "Terraform outputs:"
terraform -chdir=terraform output
success "Deployment completed successfully"