adding tags to keyvault (#45145)
This commit is contained in:
parent
9c1ba18607
commit
a5e2b60870
2 changed files with 28 additions and 3 deletions
|
@ -152,6 +152,7 @@ options:
|
||||||
|
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- azure
|
- azure
|
||||||
|
- azure_tags
|
||||||
|
|
||||||
author:
|
author:
|
||||||
- "Zim Kalinowski (@zikalino)"
|
- "Zim Kalinowski (@zikalino)"
|
||||||
|
@ -265,6 +266,7 @@ class AzureRMVaults(AzureRMModuleBase):
|
||||||
self.resource_group = None
|
self.resource_group = None
|
||||||
self.vault_name = None
|
self.vault_name = None
|
||||||
self.parameters = dict()
|
self.parameters = dict()
|
||||||
|
self.tags = None
|
||||||
|
|
||||||
self.results = dict(changed=False)
|
self.results = dict(changed=False)
|
||||||
self.mgmt_client = None
|
self.mgmt_client = None
|
||||||
|
@ -273,14 +275,14 @@ class AzureRMVaults(AzureRMModuleBase):
|
||||||
|
|
||||||
super(AzureRMVaults, self).__init__(derived_arg_spec=self.module_arg_spec,
|
super(AzureRMVaults, self).__init__(derived_arg_spec=self.module_arg_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
supports_tags=False,
|
supports_tags=True,
|
||||||
required_if=self.module_required_if)
|
required_if=self.module_required_if)
|
||||||
|
|
||||||
def exec_module(self, **kwargs):
|
def exec_module(self, **kwargs):
|
||||||
"""Main module execution method"""
|
"""Main module execution method"""
|
||||||
|
|
||||||
# translate Ansible input to SDK-formatted dict in self.parameters
|
# translate Ansible input to SDK-formatted dict in self.parameters
|
||||||
for key in list(self.module_arg_spec.keys()):
|
for key in list(self.module_arg_spec.keys()) + ['tags']:
|
||||||
if hasattr(self, key):
|
if hasattr(self, key):
|
||||||
setattr(self, key, kwargs[key])
|
setattr(self, key, kwargs[key])
|
||||||
elif kwargs[key] is not None:
|
elif kwargs[key] is not None:
|
||||||
|
@ -391,6 +393,12 @@ class AzureRMVaults(AzureRMModuleBase):
|
||||||
self.to_do = Actions.Update
|
self.to_do = Actions.Update
|
||||||
break
|
break
|
||||||
|
|
||||||
|
update_tags, newtags = self.update_tags(old_response.get('tags', dict()))
|
||||||
|
|
||||||
|
if update_tags:
|
||||||
|
self.to_do = Actions.Update
|
||||||
|
self.tags = newtags
|
||||||
|
|
||||||
if (self.to_do == Actions.Create) or (self.to_do == Actions.Update):
|
if (self.to_do == Actions.Create) or (self.to_do == Actions.Update):
|
||||||
self.log("Need to Create / Update the Key Vault instance")
|
self.log("Need to Create / Update the Key Vault instance")
|
||||||
|
|
||||||
|
@ -398,6 +406,8 @@ class AzureRMVaults(AzureRMModuleBase):
|
||||||
self.results['changed'] = True
|
self.results['changed'] = True
|
||||||
return self.results
|
return self.results
|
||||||
|
|
||||||
|
self.parameters["tags"] = self.tags
|
||||||
|
|
||||||
response = self.create_update_keyvault()
|
response = self.create_update_keyvault()
|
||||||
|
|
||||||
if not old_response:
|
if not old_response:
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
that:
|
that:
|
||||||
- output.changed == false
|
- output.changed == false
|
||||||
|
|
||||||
- name: Update existing Key Vault (add a rule)
|
- name: Update existing Key Vault (add a rule and tags)
|
||||||
azure_rm_keyvault:
|
azure_rm_keyvault:
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
vault_name: "vault{{ rpfx }}"
|
vault_name: "vault{{ rpfx }}"
|
||||||
|
@ -82,12 +82,27 @@
|
||||||
keys:
|
keys:
|
||||||
- get
|
- get
|
||||||
- list
|
- list
|
||||||
|
tags:
|
||||||
|
aaa: bbb
|
||||||
register: output
|
register: output
|
||||||
- name: Assert the state has changed
|
- name: Assert the state has changed
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- output.changed == true
|
- output.changed == true
|
||||||
|
|
||||||
|
- name: Use REST API to retrieve keyvault (as facts not available yet)
|
||||||
|
azure_rm_resource_facts:
|
||||||
|
api_version: '2018-02-14'
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
provider: keyvault
|
||||||
|
resource_type: vaults
|
||||||
|
resource_name: "vault{{ rpfx }}"
|
||||||
|
register: output
|
||||||
|
- name: Assert the facts are properly set
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- output.response[0].tags.aaa == "bbb"
|
||||||
|
|
||||||
- name: Delete instance of Key Vault -- check mode
|
- name: Delete instance of Key Vault -- check mode
|
||||||
azure_rm_keyvault:
|
azure_rm_keyvault:
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
|
|
Loading…
Reference in a new issue