fix keyvault secret bug (#60754)
* fix keyvault secret bug * remove unexpected spaces
This commit is contained in:
parent
aa5a221ddc
commit
b335303471
1 changed files with 8 additions and 5 deletions
|
@ -138,11 +138,13 @@ class AzureRMKeyVaultSecret(AzureRMModuleBase):
|
|||
changed = False
|
||||
|
||||
try:
|
||||
results['secret_id'] = self.get_secret(self.secret_name)
|
||||
results = self.get_secret(self.secret_name)
|
||||
|
||||
# Secret exists and will be deleted
|
||||
if self.state == 'absent':
|
||||
changed = True
|
||||
elif self.secret_value and results['secret_value'] != self.secret_value:
|
||||
changed = True
|
||||
|
||||
except KeyVaultErrorException:
|
||||
# Secret doesn't exist
|
||||
|
@ -155,7 +157,7 @@ class AzureRMKeyVaultSecret(AzureRMModuleBase):
|
|||
if not self.check_mode:
|
||||
# Create secret
|
||||
if self.state == 'present' and changed:
|
||||
results['secret_id'] = self.create_secret(self.secret_name, self.secret_value, self.tags)
|
||||
results['secret_id'] = self.create_update_secret(self.secret_name, self.secret_value, self.tags)
|
||||
self.results['state'] = results
|
||||
self.results['state']['status'] = 'Created'
|
||||
# Delete secret
|
||||
|
@ -205,10 +207,11 @@ class AzureRMKeyVaultSecret(AzureRMModuleBase):
|
|||
secret_bundle = self.client.get_secret(self.keyvault_uri, name, version)
|
||||
if secret_bundle:
|
||||
secret_id = KeyVaultId.parse_secret_id(secret_bundle.id)
|
||||
return secret_id.id
|
||||
return dict(secret_id=secret_id.id, secret_value=secret_bundle.value)
|
||||
return None
|
||||
|
||||
def create_secret(self, name, secret, tags):
|
||||
''' Creates a secret '''
|
||||
def create_update_secret(self, name, secret, tags):
|
||||
''' Creates/Updates a secret '''
|
||||
secret_bundle = self.client.set_secret(self.keyvault_uri, name, secret, tags)
|
||||
secret_id = KeyVaultId.parse_secret_id(secret_bundle.id)
|
||||
return secret_id.id
|
||||
|
|
Loading…
Reference in a new issue