-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_tf_backend_azure.sh
executable file
·79 lines (70 loc) · 2.11 KB
/
init_tf_backend_azure.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
#!/bin/bash
#
# The purpose of this script is to provision the resources needed to store
# terraform states on AZURE. It will provision a container on Azure Storage account as well as a
# container to support state locking and consistency checking.
#
# Official documentation about terraform state in Azure Storage Account =>
# https://developer.hashicorp.com/terraform/language/settings/backends/azurerm
# Bash strict mode
set -euo pipefail
RESOURCE_GROUP_NAME=administration
function help() {
cat <<EOF
Provision the resources needed to store terraform states on Azure.
A storage account is created and container for store state.
Usage : $0 -a STORAGE_ACCOUNT -c STORAGE_CONTAINER [options]
Mandatory arguments :
-a The name of Storage Account.
-c The name of Storage Container.
Available options :
-r The name of Ressource Group (default $RESOURCE_GROUP_NAME).
-h Display this help.
EOF
}
while getopts "h:r:a:c:s" opt; do
case "$opt" in
h)
help
exit 0
;;
r)
RESOURCE_GROUP_NAME=$OPTARG
;;
a)
STORAGE_ACCOUNT_NAME=$OPTARG
;;
c)
STORAGE_CONTAINER_NAME=$OPTARG
;;
*)
echo "Unsupported flag provided : ${opt}".
help
exit 1
;;
esac
done
if [ "$STORAGE_ACCOUNT_NAME" == "" ]; then
echo "Storage account name was not specified, aborting !"
exit 1
fi
if [ "$STORAGE_CONTAINER_NAME" == "" ]; then
echo "Storage container name was not specified, aborting !"
exit 1
fi
export AZURE_EXTENSION_USE_DYNAMIC_INSTALL=yes_without_prompt
# Create Storage Account
echo "Creating storage account : ${STORAGE_ACCOUNT_NAME}"
az storage account create \
--name "${STORAGE_ACCOUNT_NAME}" \
--resource-group "${RESOURCE_GROUP_NAME}" \
--sku Standard_LRS \
--encryption-services blob \
--output none
# Create Storage Account Container
echo "Creating Storage Account : ${STORAGE_CONTAINER_NAME}"
az storage container create \
--name "${STORAGE_CONTAINER_NAME}" \
--account-name "${STORAGE_ACCOUNT_NAME}" \
--auth-mode login \
--output none