@@ -2265,6 +2265,97 @@ def test_private_endpoint_connection_video_indexer(self, resource_group, storage
22652265 vi_name = self .create_random_name (prefix = 'clitestvideoindexer' , length = 24 )
22662266 self ._test_private_endpoint_connection_scenario (resource_group , storage_account , vi_name )
22672267
2268+ class SecurityPrivateLinkNetworkARMTemplateBasedScenarioTest (ScenarioTest ):
2269+ def _test_private_endpoint_connection_scenario (self , resource_group , target_resource_name ):
2270+ from azure .mgmt .core .tools import resource_id
2271+ resource_type = 'Microsoft.Security/privateLinks'
2272+ self .kwargs .update ({
2273+ 'target_resource_name' : target_resource_name ,
2274+ 'target_resource_id' : resource_id (subscription = self .get_subscription_id (),
2275+ resource_group = resource_group ,
2276+ namespace = resource_type .split ('/' )[0 ],
2277+ type = resource_type .split ('/' )[1 ],
2278+ name = target_resource_name ),
2279+ 'rg' : resource_group ,
2280+ 'resource_type' : resource_type ,
2281+ 'vnet' : self .create_random_name ('cli-vnet-' , 24 ),
2282+ 'subnet' : self .create_random_name ('cli-subnet-' , 24 ),
2283+ 'pe' : self .create_random_name ('cli-pe-' , 24 ),
2284+ 'pe_connection' : self .create_random_name ('cli-pec-' , 24 )
2285+ })
2286+
2287+ split_resource_type = resource_type .split ('/' )
2288+ resource_type_name = split_resource_type [0 ].split ('.' )[1 ].lower ()
2289+ resource_type_kind = split_resource_type [1 ].lower ()
2290+ param_file_name = "{}_{}_parameters.json" .format (resource_type_name , resource_type_kind )
2291+ template_file_name = "{}_{}_template.json" .format (resource_type_name , resource_type_kind )
2292+ self .kwargs .update ({
2293+ 'param_path' : os .path .join (TEST_DIR , 'private_endpoint_arm_templates' , param_file_name ),
2294+ 'template_path' : os .path .join (TEST_DIR , 'private_endpoint_arm_templates' , template_file_name )
2295+ })
2296+ self .cmd ('az deployment group create -g {rg} -p "@{param_path}" target_resource_name={target_resource_name} -f "{template_path}"' )
2297+
2298+ self .cmd ('az network vnet create -n {vnet} -g {rg} --subnet-name {subnet} -o json' ,
2299+ checks = self .check ('length(newVNet.subnets)' , 1 ))
2300+ self .cmd ('az network vnet subnet update -n {subnet} --vnet-name {vnet} -g {rg} '
2301+ '--disable-private-endpoint-network-policies true -o json' ,
2302+ checks = self .check ('privateEndpointNetworkPolicies' , 'Disabled' ))
2303+
2304+ target_private_link_resource = self .cmd ('az network private-link-resource list --name {target_resource_name} --resource-group {rg} --type {resource_type} -o json' ).get_output_in_json ()
2305+ self .kwargs .update ({
2306+ 'group_id' : target_private_link_resource [0 ]['properties' ]['groupId' ]
2307+ })
2308+ # Create a private endpoint connection
2309+ pe = self .cmd (
2310+ 'az network private-endpoint create -g {rg} -n {pe} --vnet-name {vnet} --subnet {subnet} '
2311+ '--connection-name {pe_connection} --private-connection-resource-id {target_resource_id} '
2312+ '--group-id {group_id} -o json' ).get_output_in_json ()
2313+ self .kwargs ['pe_id' ] = pe ['id' ]
2314+ self .kwargs ['pe_name' ] = self .kwargs ['pe_id' ].split ('/' )[- 1 ]
2315+
2316+ # Show the connection at cosmos db side
2317+ list_private_endpoint_conn = self .cmd ('az network private-endpoint-connection list --name {target_resource_name} --resource-group {rg} --type {resource_type} -o json' ).get_output_in_json ()
2318+ self .kwargs .update ({
2319+ "pec_id" : list_private_endpoint_conn [0 ]['id' ]
2320+ })
2321+
2322+ self .kwargs .update ({
2323+ "pec_name" : self .kwargs ['pec_id' ].split ('/' )[- 1 ]
2324+ })
2325+ self .cmd ('az network private-endpoint-connection show --id {pec_id} -o json' ,
2326+ checks = self .check ('id' , '{pec_id}' ))
2327+ self .cmd ('az network private-endpoint-connection show --resource-name {target_resource_name} --name {pec_name} --resource-group {rg} --type {resource_type} -o json' )
2328+ self .cmd ('az network private-endpoint-connection show --resource-name {target_resource_name} -n {pec_name} -g {rg} --type {resource_type} -o json' )
2329+
2330+ # Test approval/rejection
2331+ self .kwargs .update ({
2332+ 'approval_desc' : 'You are approved!' ,
2333+ 'rejection_desc' : 'You are rejected!'
2334+ })
2335+ self .cmd (
2336+ 'az network private-endpoint-connection approve --resource-name {target_resource_name} --resource-group {rg} --name {pec_name} --type {resource_type} '
2337+ '--description "{approval_desc}" -o json' , checks = [
2338+ self .check ('properties.privateLinkServiceConnectionState.status' , 'Approved' )
2339+ ])
2340+ self .cmd ('az network private-endpoint-connection reject --id {pec_id} '
2341+ '--description "{rejection_desc}" -o json' ,
2342+ checks = [
2343+ self .check ('properties.privateLinkServiceConnectionState.status' , 'Rejected' )
2344+ ])
2345+ self .cmd (
2346+ 'az network private-endpoint-connection list --name {target_resource_name} --resource-group {rg} --type {resource_type} -o json' ,
2347+ checks = [
2348+ self .check ('length(@)' , 1 )
2349+ ])
2350+
2351+ # Test delete
2352+ self .cmd ('az network private-endpoint-connection delete --id {pec_id} -y -o json' )
2353+
2354+ @live_only ()
2355+ @ResourceGroupPreparer (name_prefix = "test_private_endpoint_connection_security_privatelink" , location = "westus" )
2356+ def test_private_endpoint_connection_security_privatelink (self , resource_group ):
2357+ name = self .create_random_name (prefix = 'clitestsecuritypl' , length = 24 )
2358+ self ._test_private_endpoint_connection_scenario (resource_group , name )
22682359
22692360class NetworkPrivateLinkDigitalTwinsScenarioTest (ScenarioTest ):
22702361 @ResourceGroupPreparer (
0 commit comments