diff --git a/plugins/modules/azure_rm_keyvault.py b/plugins/modules/azure_rm_keyvault.py index 90012de4a..14946fbbe 100644 --- a/plugins/modules/azure_rm_keyvault.py +++ b/plugins/modules/azure_rm_keyvault.py @@ -194,9 +194,9 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError + from azure.core.polling import LROPoller + from azure.core.exceptions import ResourceNotFoundError from azure.mgmt.keyvault import KeyVaultManagementClient - from msrest.polling import LROPoller from msrest.serialization import Model except ImportError: # This is handled in azure_rm_common @@ -343,6 +343,7 @@ def exec_module(self, **kwargs): self.mgmt_client = self.get_mgmt_svc_client(KeyVaultManagementClient, base_url=self._cloud_environment.endpoints.resource_manager, + is_track2=True, api_version="2019-09-01") resource_group = self.get_resource_group(self.resource_group) @@ -484,13 +485,13 @@ def create_update_keyvault(self): self.log("Creating / Updating the Key Vault instance {0}".format(self.vault_name)) try: - response = self.mgmt_client.vaults.create_or_update(resource_group_name=self.resource_group, - vault_name=self.vault_name, - parameters=self.parameters) + response = self.mgmt_client.vaults.begin_create_or_update(resource_group_name=self.resource_group, + vault_name=self.vault_name, + parameters=self.parameters) if isinstance(response, LROPoller): response = self.get_poller_result(response) - except CloudError as exc: + except Exception as exc: self.log('Error attempting to create the Key Vault instance.') self.fail("Error creating the Key Vault instance: {0}".format(str(exc))) return response.as_dict() @@ -505,7 +506,7 @@ def delete_keyvault(self): try: response = self.mgmt_client.vaults.delete(resource_group_name=self.resource_group, vault_name=self.vault_name) - except CloudError as e: + except Exception as e: self.log('Error attempting to delete the Key Vault instance.') self.fail("Error deleting the Key Vault instance: {0}".format(str(e))) @@ -525,7 +526,7 @@ def get_keyvault(self): found = True self.log("Response : {0}".format(response)) self.log("Key Vault instance : {0} found".format(response.name)) - except CloudError as e: + except ResourceNotFoundError as e: self.log('Did not find the Key Vault instance.') if found is True: return response.as_dict() diff --git a/plugins/modules/azure_rm_keyvault_info.py b/plugins/modules/azure_rm_keyvault_info.py index f8f4a1d70..2c8248610 100644 --- a/plugins/modules/azure_rm_keyvault_info.py +++ b/plugins/modules/azure_rm_keyvault_info.py @@ -193,7 +193,7 @@ try: from azure.mgmt.keyvault import KeyVaultManagementClient - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -226,7 +226,7 @@ def keyvault_to_dict(vault): ) for policy in vault.properties.access_policies] if vault.properties.access_policies else None, sku=dict( family=vault.properties.sku.family, - name=vault.properties.sku.name.name + name=vault.properties.sku.name ) ) @@ -261,6 +261,7 @@ def exec_module(self, **kwargs): self._client = self.get_mgmt_svc_client(KeyVaultManagementClient, base_url=self._cloud_environment.endpoints.resource_manager, + is_track2=True, api_version="2019-09-01") if self.name: @@ -291,7 +292,7 @@ def get_by_name(self): if response and self.has_tags(response.tags, self.tags): results.append(keyvault_to_dict(response)) - except CloudError as e: + except ResourceNotFoundError as e: self.log("Did not find the key vault {0}: {1}".format(self.name, str(e))) return results @@ -312,7 +313,7 @@ def list_by_resource_group(self): for item in response: if self.has_tags(item.tags, self.tags): results.append(keyvault_to_dict(item)) - except CloudError as e: + except Exception as e: self.log("Did not find key vaults in resource group {0} : {1}.".format(self.resource_group, str(e))) return results @@ -334,7 +335,7 @@ def list(self): if self.has_tags(item.tags, self.tags): source_id = item.id.split('/') results.append(keyvault_to_dict(self._client.vaults.get(source_id[4], source_id[8]))) - except CloudError as e: + except Exception as e: self.log("Did not find key vault in current subscription {0}.".format(str(e))) return results diff --git a/requirements-azure.txt b/requirements-azure.txt index ec2b8729e..02ee2cdf3 100644 --- a/requirements-azure.txt +++ b/requirements-azure.txt @@ -17,7 +17,6 @@ azure-mgmt-containerservice==20.0.0 azure-mgmt-datalake-store==1.0.0 azure-mgmt-datafactory==2.0.0 azure-mgmt-dns==8.0.0 -azure-mgmt-keyvault==2.2.0 azure-mgmt-marketplaceordering==0.1.0 azure-mgmt-monitor==3.0.0 azure-mgmt-managedservices==6.0.0 @@ -39,6 +38,7 @@ azure-storage-blob==12.11.0 msrest==0.6.21 msrestazure==0.6.4 azure-keyvault==1.0.0a1 +azure-mgmt-keyvault==10.0.0 azure-graphrbac==0.61.1 azure-mgmt-cosmosdb==0.15.0 azure-mgmt-hdinsight==9.0.0 diff --git a/tests/integration/targets/azure_rm_diskencryptionset/tasks/main.yml b/tests/integration/targets/azure_rm_diskencryptionset/tasks/main.yml index 85420ebbe..79055e213 100644 --- a/tests/integration/targets/azure_rm_diskencryptionset/tasks/main.yml +++ b/tests/integration/targets/azure_rm_diskencryptionset/tasks/main.yml @@ -21,6 +21,7 @@ vault_tenant: "{{ tenant_id }}" sku: name: standard + family: A access_policies: - tenant_id: "{{ tenant_id }}" object_id: "{{ object_id }}"