1
1
#! /bin/bash
2
- set -euo pipefail
2
+ set -eo pipefail
3
3
IFS=$' \n\t '
4
4
5
5
for i in " $@ "
6
6
do
7
7
case $i in
8
- --subscription_id =* )
8
+ --subscription-id =* )
9
9
subscription_id=" ${i#* =} "
10
10
shift
11
11
;;
12
- --resource_group_name =* )
12
+ --resource-group-name =* )
13
13
resource_group_name=" ${i#* =} "
14
14
shift
15
15
;;
16
- --nginx_deployment_name =* )
16
+ --nginx-deployment-name =* )
17
17
nginx_deployment_name=" ${i#* =} "
18
18
shift
19
19
;;
20
+ ;;
20
21
--certificates=* )
21
22
certificates=" ${i#* =} "
22
23
shift
@@ -26,35 +27,47 @@ case $i in
26
27
shift
27
28
;;
28
29
* )
29
- echo " Not matched option '${i#* = } ' passed in."
30
+ echo " Unknown option '${i} ' passed in."
30
31
exit 1
31
32
;;
32
33
esac
33
34
done
34
35
35
- if [[ ! -v subscription_id ]] ;
36
- then
37
- echo " Please set 'subscription-id' ... "
38
- exit 1
36
+ # Validate Required Parameters
37
+ missing_params=()
38
+ if [ -z " $subscription_id " ] ; then
39
+ missing_params+=( " subscription-id " )
39
40
fi
40
- if [[ ! -v resource_group_name ]];
41
- then
42
- echo " Please set 'resource-group-name' ..."
43
- exit 1
41
+ if [ -z " $resource_group_name " ]; then
42
+ missing_params+=(" resource-group-name" )
44
43
fi
45
- if [[ ! -v nginx_deployment_name ]];
46
- then
47
- echo " Please set 'nginx-deployment-name' ..."
48
- exit 1
44
+ if [ -z " $nginx_deployment_name " ]; then
45
+ missing_params+=(" nginx-deployment-name" )
49
46
fi
50
- if [[ ! -v certificates ]];
51
- then
52
- echo " Please set 'nginx-certificates' ..."
47
+ if [ -z " $certificates " ]; then
48
+ missing_params+=(" certificates" )
49
+ fi
50
+
51
+ # Check and print if any required params are missing
52
+ if [ ${# missing_params[@]} -gt 0 ]; then
53
+ echo " Error: Missing required variables in the workflow:"
54
+ echo " ${missing_params[*]} "
53
55
exit 1
54
56
fi
55
57
58
+ # Synchronize the NGINX certificates to the NGINXaaS for Azure deployment.
59
+
60
+ echo " Synchronizing NGINX certificates"
61
+ echo " Subscription ID: $subscription_id "
62
+ echo " Resource group name: $resource_group_name "
63
+ echo " NGINXaaS for Azure deployment name: $nginx_deployment_name "
64
+ echo " "
65
+
56
66
az account set -s " $subscription_id " --verbose
57
67
68
+ echo " Installing the az nginx extension if not already installed."
69
+ az extension add --name nginx --allow-preview true
70
+
58
71
count=$( echo " $certificates " | jq ' . | length' )
59
72
for (( i= 0 ; i< count; i++ )) ;
60
73
do
63
76
nginx_key_file=$( echo " $certificates " | jq -r ' .[' " $i " ' ].keyVirtualPath' )
64
77
keyvault_secret=$( echo " $certificates " | jq -r ' .[' " $i " ' ].keyvaultSecret' )
65
78
66
- do_nginx_arm_deployment=1
67
- err_msg=" "
68
- if [ -z " $nginx_cert_name " ] || [ " $nginx_cert_name " = " null" ]
69
- then
70
- err_msg+=" nginx_cert_name is empty;"
71
- do_nginx_arm_deployment=0
79
+ # Validate certificate parameters
80
+ missing_cert_params=()
81
+ if [ -z " $nginx_cert_name " ] || [ " $nginx_cert_name " = " null" ]; then
82
+ missing_cert_params+=(" certificateName" )
72
83
fi
73
- if [ -z " $nginx_cert_file " ] || [ " $nginx_cert_file " = " null" ]
74
- then
75
- err_msg+=" nginx_cert_file is empty;"
76
- do_nginx_arm_deployment=0
84
+ if [ -z " $nginx_cert_file " ] || [ " $nginx_cert_file " = " null" ]; then
85
+ missing_cert_params+=(" certificateVirtualPath" )
77
86
fi
78
- if [ -z " $nginx_key_file " ] || [ " $nginx_key_file " = " null" ]
79
- then
80
- err_msg+=" nginx_key_file is empty;"
81
- do_nginx_arm_deployment=0
87
+ if [ -z " $nginx_key_file " ] || [ " $nginx_key_file " = " null" ]; then
88
+ missing_cert_params+=(" keyVirtualPath" )
82
89
fi
83
- if [ -z " $keyvault_secret " ] || [ " $keyvault_secret " = " null" ]
84
- then
85
- err_msg+=" keyvault_secret is empty;"
86
- do_nginx_arm_deployment=0
90
+ if [ -z " $keyvault_secret " ] || [ " $keyvault_secret " = " null" ]; then
91
+ missing_cert_params+=(" keyvaultSecret" )
87
92
fi
88
93
89
- echo " Synchronizing NGINX certificate"
90
- echo " Subscription ID: $subscription_id "
91
- echo " Resource group name: $resource_group_name "
92
- echo " NGINXaaS for Azure deployment name: $nginx_deployment_name "
93
- echo " "
94
- echo " NGINXaaS for Azure cert name: $nginx_cert_name "
95
- echo " NGINXaaS for Azure cert file location: $nginx_cert_file "
96
- echo " NGINXaaS for Azure key file location: $nginx_key_file "
94
+ if [ ${# missing_cert_params[@]} -gt 0 ]; then
95
+ echo " Skipping certificate $i deployment due to missing parameters:"
96
+ echo " ${missing_cert_params[*]} "
97
+ echo " "
98
+ continue
99
+ fi
100
+
101
+ echo " Processing certificate: $nginx_cert_name "
102
+ echo " Certificate file location: $nginx_cert_file "
103
+ echo " Key file location: $nginx_key_file "
97
104
echo " "
98
105
99
- echo " Installing the az nginx extension if not already installed."
100
- az extension add --name nginx --allow-preview true
106
+ az_cmd=(
107
+ " az"
108
+ " nginx"
109
+ " deployment"
110
+ " certificate"
111
+ " create"
112
+ " --resource-group" " $resource_group_name "
113
+ " --certificate-name" " $nginx_cert_name "
114
+ " --deployment-name" " $nginx_deployment_name "
115
+ " --certificate-path" " $nginx_cert_file "
116
+ " --key-path" " $nginx_key_file "
117
+ " --key-vault-secret-id" " $keyvault_secret "
118
+ " --verbose"
119
+ )
101
120
102
- if [ $do_nginx_arm_deployment -eq 1 ]
103
- then
104
- az_cmd=(
105
- " az"
106
- " nginx"
107
- " deployment"
108
- " certificate"
109
- " create"
110
- " --resource-group" " $resource_group_name "
111
- " --certificate-name" " $nginx_cert_name "
112
- " --deployment-name" " $nginx_deployment_name "
113
- " --certificate-path" " $nginx_cert_file "
114
- " --key-path" " $nginx_key_file "
115
- " --key-vault-secret-id" " $keyvault_secret "
116
- " --verbose"
117
- )
118
- if [[ " $debug " == true ]]; then
119
- az_cmd+=(" --debug" )
120
- echo " ${az_cmd[@]} "
121
- fi
122
- set +e
123
- " ${az_cmd[@]} "
124
- set -e
125
- else
126
- echo " Skipping JSON object $i cert deployment with error:$err_msg "
127
- echo " "
121
+ if [[ " $debug " == true ]]; then
122
+ az_cmd+=(" --debug" )
123
+ echo " ${az_cmd[@]} "
128
124
fi
125
+
126
+ " ${az_cmd[@]} "
129
127
done
0 commit comments