@@ -78,19 +78,19 @@ function mgmtstorage_remove_network_exception() {
78
78
}
79
79
80
80
function get_resource_group_name() {
81
- if [[ -z " ${MGMT_RESOURCE_GROUP_NAME :- } " ]]; then
82
- echo -e " Error: MGMT_RESOURCE_GROUP_NAME is not set\nExiting...\n" >&2
81
+ if [[ -z " ${TF_VAR_mgmt_resource_group_name :- } " ]]; then
82
+ echo -e " Error: TF_VAR_mgmt_resource_group_name is not set\nExiting...\n" >&2
83
83
exit 1
84
84
fi
85
- echo " $MGMT_RESOURCE_GROUP_NAME "
85
+ echo " $TF_VAR_mgmt_resource_group_name "
86
86
}
87
87
88
88
function get_storage_account_name() {
89
- if [[ -z " ${MGMT_STORAGE_ACCOUNT_NAME :- } " ]]; then
90
- echo -e " Error: MGMT_STORAGE_ACCOUNT_NAME is not set\nExiting...\n" >&2
89
+ if [[ -z " ${TF_VAR_mgmt_storage_account_name :- } " ]]; then
90
+ echo -e " Error: TF_VAR_mgmt_storage_account_name is not set\nExiting...\n" >&2
91
91
exit 1
92
92
fi
93
- echo " $MGMT_STORAGE_ACCOUNT_NAME "
93
+ echo " $TF_VAR_mgmt_storage_account_name "
94
94
}
95
95
96
96
function get_my_ip() {
@@ -99,7 +99,7 @@ function get_my_ip() {
99
99
else
100
100
local MY_IP
101
101
MY_IP=$( curl -s " https://ipecho.net/plain" ) || { echo " Error: Failed to fetch IP address" >&2 ; exit 1; }
102
-
102
+
103
103
if [[ -z " $MY_IP " ]]; then
104
104
echo " Error: Could not determine IP address." >&2
105
105
exit 1
@@ -123,10 +123,18 @@ function is_ip_in_network_rule() {
123
123
COUNT=$( az storage account network-rule list --resource-group " $RESOURCE_GROUP " --account-name " $SA_NAME " --query " length(ipRules[?ipAddressOrRange=='$MY_IP '])" --output tsv)
124
124
125
125
if [[ " $COUNT " -gt 0 ]]; then
126
- # Step 2: Try accessing storage to confirm access
127
- if az storage container list --account-name " $SA_NAME " --auth-mode login --output none 2> /dev/null; then
128
- return 0 # Success: IP is in rules AND access is confirmed
126
+ # Step 2: Verify storage accessibility by listing containers...
127
+ containers=$( az storage container list --account-name " $SA_NAME " --auth-mode login --query " [].name" --output tsv)
128
+ if [[ -z " $containers " ]]; then
129
+ # No containers found, assume success.
130
+ return 0
129
131
fi
132
+ for container in $containers ; do
133
+ if ! az storage blob list --container-name " $container " --account-name " $SA_NAME " --auth-mode login --output none; then
134
+ return 1 # Failure if blob listing fails in any container
135
+ fi
136
+ done
137
+ return 0 # Success if blob list works for all containers
130
138
fi
131
139
132
140
return 1 # Either rule not added or access is still restricted
0 commit comments