From 4292c33649556b733da6ffe9939f84a6a2632fb7 Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Thu, 21 Feb 2019 08:17:45 +0800 Subject: [PATCH] adding tags to azure_rm_sqldatabase (#52615) * adding tags to sql database * can't add version_added, so have to ignore sanity test * removed ignore --- .../modules/cloud/azure/azure_rm_sqldatabase.py | 10 ++++++++-- .../targets/azure_rm_sqlserver/tasks/main.yml | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py b/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py index 3802c5c5fb3..a51818747c2 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py @@ -135,6 +135,7 @@ options: extends_documentation_fragment: - azure + - azure_tags author: - "Zim Kalinowski (@zikalino)" @@ -301,6 +302,7 @@ class AzureRMDatabases(AzureRMModuleBase): self.server_name = None self.name = None self.parameters = dict() + self.tags = None self.results = dict(changed=False) self.state = None @@ -308,12 +310,12 @@ class AzureRMDatabases(AzureRMModuleBase): super(AzureRMDatabases, self).__init__(derived_arg_spec=self.module_arg_spec, supports_check_mode=True, - supports_tags=False) + supports_tags=True) def exec_module(self, **kwargs): """Main module execution method""" - for key in list(self.module_arg_spec.keys()): + for key in list(self.module_arg_spec.keys()) + ['tags']: if hasattr(self, key): setattr(self, key, kwargs[key]) elif kwargs[key] is not None: @@ -380,6 +382,9 @@ class AzureRMDatabases(AzureRMModuleBase): if (('edition' in self.parameters) and (self.parameters['edition'] != old_response['edition'])): self.to_do = Actions.Update + update_tags, newtags = self.update_tags(old_response.get('tags', dict())) + if update_tags: + self.tags = newtags if (self.to_do == Actions.Create) or (self.to_do == Actions.Update): self.log("Need to Create / Update the SQL Database instance") @@ -388,6 +393,7 @@ class AzureRMDatabases(AzureRMModuleBase): self.results['changed'] = True return self.results + self.parameters['tags'] = self.tags response = self.create_update_sqldatabase() if not old_response: diff --git a/test/integration/targets/azure_rm_sqlserver/tasks/main.yml b/test/integration/targets/azure_rm_sqlserver/tasks/main.yml index b081ffa8007..a85e25efb16 100644 --- a/test/integration/targets/azure_rm_sqlserver/tasks/main.yml +++ b/test/integration/targets/azure_rm_sqlserver/tasks/main.yml @@ -117,6 +117,8 @@ server_name: sqlsrv{{ random_postfix }} name: database{{ random_postfix }} location: eastus + tags: + aaa: bbb register: output - name: Assert the resource instance is well created assert: @@ -130,6 +132,8 @@ server_name: sqlsrv{{ random_postfix }} name: database{{ random_postfix }} location: eastus + tags: + aaa: bbb register: output - name: Assert the state has not changed assert: