diff --git a/plugins/modules/azure_rm_appgateway_info.py b/plugins/modules/azure_rm_appgateway_info.py index 9fa86438b..f34bf86a1 100644 --- a/plugins/modules/azure_rm_appgateway_info.py +++ b/plugins/modules/azure_rm_appgateway_info.py @@ -94,7 +94,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError from azure.mgmt.network import NetworkManagementClient from msrestazure.tools import parse_resource_id except ImportError: @@ -117,7 +117,6 @@ def __init__(self): self.name = None self.resource_group = None - self.mgmt_client = None super(AzureRMApplicationGatewayInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, @@ -128,9 +127,6 @@ def exec_module(self, **kwargs): for key in self.module_arg_spec: setattr(self, key, kwargs[key]) - self.mgmt_client = self.get_mgmt_svc_client(NetworkManagementClient, - base_url=self._cloud_environment.endpoints.resource_manager) - if self.name is not None: self.results["gateways"] = self.get() elif self.resource_group is not None: @@ -144,8 +140,8 @@ def get(self): response = None results = [] try: - response = self.mgmt_client.application_gateways.get(resource_group_name=self.resource_group, application_gateway_name=self.name) - except CloudError: + response = self.network_client.application_gateways.get(resource_group_name=self.resource_group, application_gateway_name=self.name) + except ResourceNotFoundError: pass if response is not None: @@ -157,8 +153,8 @@ def list_by_rg(self): response = None results = [] try: - response = self.mgmt_client.application_gateways.list(resource_group_name=self.resource_group) - except CloudError as exc: + response = self.network_client.application_gateways.list(resource_group_name=self.resource_group) + except Exception as exc: request_id = exc.request_id if exc.request_id else '' self.fail("Error listing application gateways in resource groups {0}: {1} - {2}".format(self.resource_group, request_id, str(exc))) @@ -171,8 +167,8 @@ def list_all(self): response = None results = [] try: - response = self.mgmt_client.application_gateways.list_all() - except CloudError as exc: + response = self.network_client.application_gateways.list_all() + except Exception as exc: request_id = exc.request_id if exc.request_id else '' self.fail("Error listing all application gateways: {0} - {1}".format(request_id, str(exc)))