diff --git a/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py b/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py index 07326095f9e..978c2f3c3a6 100644 --- a/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/private_link_resource_and_endpoint_connections/custom.py @@ -25,6 +25,7 @@ def register_providers(): _register_one_provider('Microsoft.CognitiveServices/accounts', '2022-03-01', True) _register_one_provider('Microsoft.Compute/diskAccesses', '2020-09-30', True) _register_one_provider('Microsoft.ContainerRegistry/registries', '2019-12-01-preview', True) + _register_one_provider('Microsoft.Dashboard/grafana', '2022-05-01-preview', True) _register_one_provider('Microsoft.DBforMySQL/servers', '2018-06-01', False, '2017-12-01-preview') _register_one_provider('Microsoft.DBforMariaDB/servers', '2018-06-01', False) _register_one_provider('Microsoft.DBforPostgreSQL/servers', '2018-06-01', False, '2017-12-01-preview') diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py index 579f88f81a7..0e1a21fedcd 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py @@ -3241,5 +3241,71 @@ def test_private_endpoint_pls(self): self.cmd('network private-endpoint-connection delete -g {rg} --resource-name {pls} -n {request1} --type {type} --yes') +class NetworkPrivateLinkManagedGrafanaScenarioTest(ScenarioTest): + @live_only() + @ResourceGroupPreparer(name_prefix='test_grafana_private_endpoint_', random_name_length=40) + def test_private_endpoint_connection_grafana(self, resource_group): + self.kwargs.update({ + 'resource_group': resource_group, + 'service_name': self.create_random_name('cli-test-srv-', 22), + 'vnet_name': self.create_random_name('cli-test-vnet-', 22), + 'subnet_name': self.create_random_name('cli-test-subnet-', 22), + 'endpoint_name': self.create_random_name('cli-test-pe-', 22), + 'endpoint_conn_name': self.create_random_name('cli-test-pec-', 22), + 'location': "eastus2euap", + }) + + # Install extension for Azure Managed Grafana Service + self.cmd('extension add -n amg') + + # Create Azure Managed Grafana Service + service_created = self.cmd( + 'grafana create -g {resource_group} -n {service_name} --l {location}').get_output_in_json() + self.kwargs['service_id'] = service_created['id'] + + # Check private link resource is available + self.cmd('network private-link-resource list --id {service_id}', checks=[ + self.check('length(@)', 1), + ]) + + # Prepare network + self.cmd('network vnet create -n {vnet_name} -g {resource_group} --subnet-name {subnet_name}', + checks=self.check('length(newVNet.subnets)', 1)) + self.cmd('network vnet subnet update -n {subnet_name} --vnet-name {vnet_name} -g {resource_group} ' + '--disable-private-endpoint-network-policies true', + checks=self.check('privateEndpointNetworkPolicies', 'Disabled')) + + result = self.cmd( + 'network vnet subnet show -n {subnet_name} --vnet-name {vnet_name} -g {resource_group} ').get_output_in_json() + + # Create private endpoint + result = self.cmd( + 'network private-endpoint create -g {resource_group} -n {endpoint_name} --vnet-name {vnet_name} --subnet {subnet_name} ' + '--connection-name {endpoint_conn_name} --private-connection-resource-id {service_id} ' + '--group-id Gateway').get_output_in_json() + self.assertTrue( + self.kwargs['endpoint_name'].lower() in result['name'].lower()) + + result = self.cmd( + 'network private-endpoint-connection list -g {resource_group} -n {service_name} --type Microsoft.Dashboard/grafana', + checks=[self.check('length(@)', 1), ]).get_output_in_json() + self.kwargs.update({ + "endpoint_request": result[0]['name'], + "pec_id": result[0]['id'], + "pec_name": result[0]['id'].split('/')[-1] + }) + + # Show the private endpoint connection + self.cmd('az network private-endpoint-connection show --id {pec_id}', + checks=self.check('id', '{pec_id}')) + + self.cmd('az network private-endpoint-connection show --resource-name {service_name} -n {pec_name} -g {resource_group} --type Microsoft.Dashboard/grafana', + checks=self.check('id', '{pec_id}')) + + # Remove private endpoint + self.cmd( + 'network private-endpoint-connection delete -g {resource_group} --resource-name {service_name} -n {endpoint_request} --type Microsoft.Dashboard/grafana -y') + + if __name__ == '__main__': unittest.main()