@@ -42,13 +42,13 @@ def _create_afd_apim_pe_infrastructure(
42
42
rg_tags = utils .build_infrastructure_tags (deployment )
43
43
apim_network_mode = APIMNetworkMode .EXTERNAL_VNET
44
44
45
- print (f" \n 🚀 Creating AFD-APIM-PE infrastructure..." )
46
- print (f" Location : { rg_location } " )
47
- print (f" Index : { index } " )
48
- print (f" Infrastructure : { deployment .value } " )
49
- print (f" APIM SKU : { apim_sku .value } " )
50
- print (f" Use ACA : { use_aca } " )
51
- print (f" Resource Group : { rg_name } \n " )
45
+ print (f' \n 🚀 Creating AFD-APIM-PE infrastructure...' )
46
+ print (f' Location : { rg_location } ' )
47
+ print (f' Index : { index } ' )
48
+ print (f' Infrastructure : { deployment .value } ' )
49
+ print (f' APIM SKU : { apim_sku .value } ' )
50
+ print (f' Use ACA : { use_aca } ' )
51
+ print (f' Resource Group : { rg_name } \n ' )
52
52
53
53
# 2) Set up the policy fragments
54
54
if custom_policy_fragments is None :
@@ -109,62 +109,62 @@ def _create_afd_apim_pe_infrastructure(
109
109
110
110
try :
111
111
os .chdir (infra_dir )
112
- print (f" 📁 Changed working directory to: { infra_dir } " )
112
+ print (f' 📁 Changed working directory to: { infra_dir } ' )
113
113
114
114
# 6) Create the resource group if it doesn't exist
115
115
utils .create_resource_group (rg_name , rg_location , rg_tags )
116
116
117
117
# 7) First deployment with public access enabled
118
- print (" \n 🚀 Phase 1: Creating infrastructure with public access enabled..." )
118
+ print (' \n 🚀 Phase 1: Creating infrastructure with public access enabled...' )
119
119
output = utils .create_bicep_deployment_group (rg_name , rg_location , deployment , bicep_parameters )
120
120
121
121
if not output .success :
122
- print (" ❌ Phase 1 deployment failed!" )
122
+ print (' ❌ Phase 1 deployment failed!' )
123
123
return output
124
124
125
125
# Extract service details for private link approval
126
126
if output .json_data :
127
127
apim_service_id = output .get ('apimServiceId' , 'APIM Service Id' , suppress_logging = True )
128
128
129
- print (" ✅ Phase 1 deployment completed successfully!" )
129
+ print (' ✅ Phase 1 deployment completed successfully!' )
130
130
131
131
# 8) Approve private link connections
132
- print (" \n 🔗 Approving Front Door private link connections..." )
132
+ print (' \n 🔗 Approving Front Door private link connections...' )
133
133
_approve_private_link_connections (apim_service_id )
134
134
135
135
# 9) Second deployment to disable public access
136
- print (" \n 🔒 Phase 2: Disabling APIM public access..." )
136
+ print (' \n 🔒 Phase 2: Disabling APIM public access...' )
137
137
bicep_parameters ['apimPublicAccess' ]['value' ] = False
138
138
139
139
output = utils .create_bicep_deployment_group (rg_name , rg_location , deployment , bicep_parameters )
140
140
141
141
if output .success :
142
- print (" \n ✅ Infrastructure creation completed successfully!" )
142
+ print (' \n ✅ Infrastructure creation completed successfully!' )
143
143
if output .json_data :
144
144
apim_gateway_url = output .get ('apimResourceGatewayURL' , 'APIM API Gateway URL' , suppress_logging = True )
145
145
afd_endpoint_url = output .get ('fdeSecureUrl' , 'Front Door Endpoint URL' , suppress_logging = True )
146
146
apim_apis = output .getJson ('apiOutputs' , 'APIs' , suppress_logging = True )
147
147
148
- print (f" \n 📋 Infrastructure Details:" )
149
- print (f" Resource Group : { rg_name } " )
150
- print (f" Location : { rg_location } " )
151
- print (f" APIM SKU : { apim_sku .value } " )
152
- print (f" Use ACA : { use_aca } " )
153
- print (f" Gateway URL : { apim_gateway_url } " )
154
- print (f" Front Door URL : { afd_endpoint_url } " )
155
- print (f" APIs Created : { len (apim_apis )} " )
148
+ print (f' \n 📋 Infrastructure Details:' )
149
+ print (f' Resource Group : { rg_name } ' )
150
+ print (f' Location : { rg_location } ' )
151
+ print (f' APIM SKU : { apim_sku .value } ' )
152
+ print (f' Use ACA : { use_aca } ' )
153
+ print (f' Gateway URL : { apim_gateway_url } ' )
154
+ print (f' Front Door URL : { afd_endpoint_url } ' )
155
+ print (f' APIs Created : { len (apim_apis )} ' )
156
156
157
157
# Perform basic verification
158
- _verify_infrastructure (rg_name , afd_endpoint_url , apim_gateway_url , use_aca )
158
+ _verify_infrastructure (rg_name , use_aca )
159
159
else :
160
- print (" ❌ Phase 2 deployment failed!" )
160
+ print (' ❌ Phase 2 deployment failed!' )
161
161
162
162
return output
163
163
164
164
finally :
165
165
# Always restore the original working directory
166
166
os .chdir (original_cwd )
167
- print (f" 📁 Restored working directory to: { original_cwd } " )
167
+ print (f' 📁 Restored working directory to: { original_cwd } ' )
168
168
169
169
def _approve_private_link_connections (apim_service_id : str ) -> None :
170
170
"""
@@ -175,7 +175,7 @@ def _approve_private_link_connections(apim_service_id: str) -> None:
175
175
"""
176
176
177
177
# Get all pending private endpoint connections as JSON
178
- output = utils .run (f"az network private-endpoint-connection list --id { apim_service_id } --query \" [?contains(properties.privateLinkServiceConnectionState.status, 'Pending')]\" -o json" , print_command_to_run = False )
178
+ output = utils .run (f"az network private-endpoint-connection list --id { apim_service_id } --query \" [?contains(properties.privateLinkServiceConnectionState.status, 'Pending')]\' - o json ' , print_command_to_run = False )
179
179
180
180
# Handle both a single object and a list of objects
181
181
pending_connections = output .json_data if output .success and output .is_json else []
@@ -184,80 +184,78 @@ def _approve_private_link_connections(apim_service_id: str) -> None:
184
184
pending_connections = [pending_connections ]
185
185
186
186
total = len (pending_connections )
187
- print (f" Found { total } pending private link service connection(s)." )
187
+ print (f' Found { total } pending private link service connection(s).' )
188
188
189
189
if total > 0 :
190
190
for i , conn in enumerate (pending_connections , 1 ):
191
191
conn_id = conn .get ('id' )
192
192
conn_name = conn .get ('name' , '<unknown>' )
193
- print (f" { i } /{ total } : Approving { conn_name } " )
193
+ print (f' { i } /{ total } : Approving { conn_name } ' )
194
194
195
195
approve_result = utils .run (
196
196
f"az network private-endpoint-connection approve --id { conn_id } --description 'Approved'" ,
197
- f" Private Link Connection approved: { conn_name } " ,
198
- f" Failed to approve Private Link Connection: { conn_name } " ,
197
+ f' Private Link Connection approved: { conn_name } ' ,
198
+ f' Failed to approve Private Link Connection: { conn_name } ' ,
199
199
print_command_to_run = False
200
200
)
201
201
202
- print (" ✅ Private link approvals completed" )
202
+ print (' ✅ Private link approvals completed' )
203
203
else :
204
- print (" No pending private link service connections found. Nothing to approve." )
204
+ print (' No pending private link service connections found. Nothing to approve.' )
205
205
206
- def _verify_infrastructure (rg_name : str , afd_endpoint_url : str , apim_gateway_url : str , use_aca : bool ) -> bool :
206
+ def _verify_infrastructure (rg_name : str , use_aca : bool ) -> bool :
207
207
"""
208
208
Verify that the infrastructure was created successfully.
209
209
210
210
Args:
211
211
rg_name (str): Resource group name.
212
- afd_endpoint_url (str): Azure Front Door endpoint URL.
213
- apim_gateway_url (str): API Management gateway URL.
214
212
use_aca (bool): Whether Container Apps were included.
215
213
216
214
Returns:
217
215
bool: True if verification passed, False otherwise.
218
216
"""
219
217
220
- print (" \n 🔍 Verifying infrastructure..." )
218
+ print (' \n 🔍 Verifying infrastructure...' )
221
219
222
220
try :
223
221
# Check if the resource group exists
224
222
if not utils .does_resource_group_exist (rg_name ):
225
- print (" ❌ Resource group does not exist!" )
223
+ print (' ❌ Resource group does not exist!' )
226
224
return False
227
225
228
- print (" ✅ Resource group verified" )
226
+ print (' ✅ Resource group verified' )
229
227
230
228
# Get APIM service details
231
- output = utils .run (f'az apim list -g { rg_name } --query " [0]" -o json' , print_command_to_run = False , print_errors = False )
229
+ output = utils .run (f'az apim list -g { rg_name } --query ' [0 ]' -o json' , print_command_to_run = False , print_errors = False )
232
230
233
231
if output .success and output .json_data :
234
232
apim_name = output .json_data .get ('name' )
235
- print (f" ✅ APIM Service verified: { apim_name } " )
233
+ print (f' ✅ APIM Service verified: { apim_name } ' )
236
234
237
235
# Check Front Door
238
- afd_output = utils .run (f'az afd profile list -g { rg_name } --query " [0]" -o json' , print_command_to_run = False , print_errors = False )
236
+ afd_output = utils .run (f'az afd profile list -g { rg_name } --query ' [0 ]' -o json' , print_command_to_run = False , print_errors = False )
239
237
240
238
if afd_output .success and afd_output .json_data :
241
239
afd_name = afd_output .json_data .get ('name' )
242
- print (f" ✅ Azure Front Door verified: { afd_name } " )
240
+ print (f' ✅ Azure Front Door verified: { afd_name } ' )
243
241
244
242
# Check Container Apps if enabled
245
243
if use_aca :
246
- aca_output = utils .run (f'az containerapp list -g { rg_name } --query " length(@)" ' , print_command_to_run = False , print_errors = False )
244
+ aca_output = utils .run (f'az containerapp list -g { rg_name } --query ' length (@)' ' , print_command_to_run = False , print_errors = False )
247
245
248
246
if aca_output .success :
249
247
aca_count = int (aca_output .text .strip ())
250
- print (f" ✅ Container Apps verified: { aca_count } app(s) created" )
248
+ print (f' ✅ Container Apps verified: { aca_count } app(s) created' )
251
249
252
- print (" \n 🎉 Infrastructure verification completed successfully!" )
250
+ print (' \n 🎉 Infrastructure verification completed successfully!' )
253
251
return True
254
252
255
253
else :
256
- print (" \n ❌ APIM service not found!" )
254
+ print (' \n ❌ APIM service not found!' )
257
255
return False
258
256
259
257
except Exception as e :
260
- print (f" \n ⚠️ Verification failed with error: { str (e )} " )
258
+ print (f' \n ⚠️ Verification failed with error: { str (e )} ' )
261
259
return False
262
260
263
261
def main ():
@@ -288,14 +286,14 @@ def main():
288
286
)
289
287
290
288
if result .success :
291
- print (" \n 🎉 Infrastructure creation completed successfully!" )
289
+ print (' \n 🎉 Infrastructure creation completed successfully!' )
292
290
sys .exit (0 )
293
291
else :
294
- print (" \n 💥 Infrastructure creation failed!" )
292
+ print (' \n 💥 Infrastructure creation failed!' )
295
293
sys .exit (1 )
296
294
297
295
except Exception as e :
298
- print (f" \n 💥 Error: { str (e )} " )
296
+ print (f' \n 💥 Error: { str (e )} ' )
299
297
sys .exit (1 )
300
298
301
299
0 commit comments