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