-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·69 lines (55 loc) · 1.93 KB
/
deploy.sh
File metadata and controls
executable file
·69 lines (55 loc) · 1.93 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
#!/bin/bash
# Variables
PREFIX='local'
SUFFIX='test'
LOCATION='westeurope'
SERVICEBUS_QUEUE_NAME="myqueue" # Queue name is hardcoded in the application properties
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Change the current directory to the script's directory
cd "$CURRENT_DIR" || exit
# Intialize Terraform
echo "Initializing Terraform..."
terraform init -upgrade
# Run terraform plan and check for errors
echo "Planning Terraform deployment..."
terraform plan -out=tfplan \
-var "prefix=$PREFIX" \
-var "suffix=$SUFFIX" \
-var "location=$LOCATION" \
-var "queue_name=$SERVICEBUS_QUEUE_NAME"
if [[ $? != 0 ]]; then
echo "Terraform plan failed. Exiting."
exit 1
fi
# Apply the Terraform configuration
echo "Applying Terraform configuration..."
terraform apply -auto-approve tfplan
if [[ $? != 0 ]]; then
echo "Terraform apply failed. Exiting."
exit 1
fi
# Get the output values
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
SERVICEBUS_NAMESPACE_NAME=$(terraform output -raw namespace_name)
if [[ -z "$SERVICEBUS_NAMESPACE_NAME" ]]; then
echo "Service Bus Namespace Name is empty. Exiting."
exit 1
fi
# Retrieve the connection string for the Service Bus namespace
echo "Retrieving connection string for [$SERVICEBUS_NAMESPACE_NAME] Service Bus namespace..."
AZURE_SERVICEBUS_CONNECTION_STRING=$(az servicebus namespace authorization-rule keys list \
--resource-group "$RESOURCE_GROUP_NAME" \
--namespace-name "$SERVICEBUS_NAMESPACE_NAME" \
--name RootManageSharedAccessKey \
--query primaryConnectionString \
--output tsv)
if [[ $? -eq 0 ]] && [[ -n "$AZURE_SERVICEBUS_CONNECTION_STRING" ]]; then
export AZURE_SERVICEBUS_CONNECTION_STRING
echo "Connection string retrieved successfully."
else
echo "Failed to retrieve connection string."
exit 1
fi
# Start the Java application
echo "Starting Java application..."
cd "$CURRENT_DIR/../app" && mvn clean spring-boot:run