From 7f40baaa7c78b8900e639ebacb468ed301656148 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 21 Mar 2023 11:43:27 +0800 Subject: [PATCH 1/3] Support tags to azure_rm_servicebus.py --- plugins/modules/azure_rm_servicebus.py | 26 ++++++++++++++++--- plugins/modules/azure_rm_servicebusqueue.py | 1 - .../modules/azure_rm_servicebussaspolicy.py | 1 - plugins/modules/azure_rm_servicebustopic.py | 1 - .../azure_rm_servicebustopicsubscription.py | 1 - .../azure_rm_servicebus/tasks/main.yml | 5 +++- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/plugins/modules/azure_rm_servicebus.py b/plugins/modules/azure_rm_servicebus.py index f3f57cf5c..07db88849 100644 --- a/plugins/modules/azure_rm_servicebus.py +++ b/plugins/modules/azure_rm_servicebus.py @@ -57,6 +57,8 @@ azure_rm_servicebus: name: deadbeef location: eastus + tags: + key1: value1 ''' RETURN = ''' id: @@ -102,11 +104,12 @@ def __init__(self): ) super(AzureRMServiceBus, self).__init__(self.module_arg_spec, + supports_tags=True, supports_check_mode=True) def exec_module(self, **kwargs): - for key in list(self.module_arg_spec.keys()): + for key in list(self.module_arg_spec.keys()) + ['tags']: setattr(self, key, kwargs[key]) changed = False @@ -116,11 +119,25 @@ def exec_module(self, **kwargs): self.location = resource_group.location original = self.get() - if self.state == 'present' and not original: + + if not original: self.check_name() - changed = True + + if self.state == 'present': if not self.check_mode: - original = self.create() + if original: + update_tags, new_tags = self.update_tags(original.tags) + if update_tags: + changed = True + self.tags = new_tags + original = self.create() + else: + changed = False + else: + changed = True + original = self.create() + else: + changed = True elif self.state == 'absent' and original: changed = True original = None @@ -148,6 +165,7 @@ def create(self): poller = self.servicebus_client.namespaces.begin_create_or_update(self.resource_group, self.name, self.servicebus_models.SBNamespace(location=self.location, + tags=self.tags, sku=sku)) ns = self.get_poller_result(poller) except Exception as exc: diff --git a/plugins/modules/azure_rm_servicebusqueue.py b/plugins/modules/azure_rm_servicebusqueue.py index a86abc49b..38f0668e5 100644 --- a/plugins/modules/azure_rm_servicebusqueue.py +++ b/plugins/modules/azure_rm_servicebusqueue.py @@ -108,7 +108,6 @@ - receive_disabled extends_documentation_fragment: - azure.azcollection.azure - - azure.azcollection.azure_tags author: - Yuwei Zhou (@yuwzho) diff --git a/plugins/modules/azure_rm_servicebussaspolicy.py b/plugins/modules/azure_rm_servicebussaspolicy.py index 0808ee338..4c5083b11 100644 --- a/plugins/modules/azure_rm_servicebussaspolicy.py +++ b/plugins/modules/azure_rm_servicebussaspolicy.py @@ -66,7 +66,6 @@ extends_documentation_fragment: - azure.azcollection.azure - - azure.azcollection.azure_tags author: - Yuwei Zhou (@yuwzho) diff --git a/plugins/modules/azure_rm_servicebustopic.py b/plugins/modules/azure_rm_servicebustopic.py index 11937cecf..0bd15d5a4 100644 --- a/plugins/modules/azure_rm_servicebustopic.py +++ b/plugins/modules/azure_rm_servicebustopic.py @@ -88,7 +88,6 @@ extends_documentation_fragment: - azure.azcollection.azure - - azure.azcollection.azure_tags author: - Yuwei Zhou (@yuwzho) diff --git a/plugins/modules/azure_rm_servicebustopicsubscription.py b/plugins/modules/azure_rm_servicebustopicsubscription.py index ea9ef1d56..f01416a5a 100644 --- a/plugins/modules/azure_rm_servicebustopicsubscription.py +++ b/plugins/modules/azure_rm_servicebustopicsubscription.py @@ -100,7 +100,6 @@ extends_documentation_fragment: - azure.azcollection.azure - - azure.azcollection.azure_tags author: - Yuwei Zhou (@yuwzho) diff --git a/tests/integration/targets/azure_rm_servicebus/tasks/main.yml b/tests/integration/targets/azure_rm_servicebus/tasks/main.yml index 93f56ebb2..11c2208aa 100644 --- a/tests/integration/targets/azure_rm_servicebus/tasks/main.yml +++ b/tests/integration/targets/azure_rm_servicebus/tasks/main.yml @@ -7,12 +7,15 @@ azure_rm_servicebus: name: "ns{{ rpfx }}" resource_group: "{{ resource_group }}" + tags: + key1: value1 register: namespace - assert: that: - namespace.id - namespace.changed + - namespace.tags - name: Create a namespace (idempontent) azure_rm_servicebus: @@ -166,4 +169,4 @@ azure_rm_servicebus: name: "ns{{ rpfx }}" resource_group: "{{ resource_group }}" - state: absent \ No newline at end of file + state: absent From 11144a169ab9fa275a29fc3ba3e2f3fdb05b241c Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 21 Mar 2023 13:39:16 +0800 Subject: [PATCH 2/3] Fix sanity fail --- plugins/modules/azure_rm_servicebusqueue.py | 1 + plugins/modules/azure_rm_servicebussaspolicy.py | 1 + plugins/modules/azure_rm_servicebustopic.py | 1 + 3 files changed, 3 insertions(+) diff --git a/plugins/modules/azure_rm_servicebusqueue.py b/plugins/modules/azure_rm_servicebusqueue.py index 38f0668e5..f50693cf3 100644 --- a/plugins/modules/azure_rm_servicebusqueue.py +++ b/plugins/modules/azure_rm_servicebusqueue.py @@ -213,6 +213,7 @@ def __init__(self): ) super(AzureRMServiceBusQueue, self).__init__(self.module_arg_spec, + supports_tags=False, supports_check_mode=True) def exec_module(self, **kwargs): diff --git a/plugins/modules/azure_rm_servicebussaspolicy.py b/plugins/modules/azure_rm_servicebussaspolicy.py index 4c5083b11..3acb2f479 100644 --- a/plugins/modules/azure_rm_servicebussaspolicy.py +++ b/plugins/modules/azure_rm_servicebussaspolicy.py @@ -198,6 +198,7 @@ def __init__(self): super(AzureRMServiceBusSASPolicy, self).__init__(self.module_arg_spec, mutually_exclusive=mutually_exclusive, required_if=required_if, + supports_tags=False, supports_check_mode=True) def exec_module(self, **kwargs): diff --git a/plugins/modules/azure_rm_servicebustopic.py b/plugins/modules/azure_rm_servicebustopic.py index 0bd15d5a4..8d81d0f22 100644 --- a/plugins/modules/azure_rm_servicebustopic.py +++ b/plugins/modules/azure_rm_servicebustopic.py @@ -179,6 +179,7 @@ def __init__(self): ) super(AzureRMServiceBusTopic, self).__init__(self.module_arg_spec, + supports_tags=False, supports_check_mode=True) def exec_module(self, **kwargs): From 30e9ef726ad7e1a789cd657c02e1d9ca8fa75a13 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 21 Mar 2023 13:48:50 +0800 Subject: [PATCH 3/3] small sanity change --- plugins/modules/azure_rm_servicebustopicsubscription.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/azure_rm_servicebustopicsubscription.py b/plugins/modules/azure_rm_servicebustopicsubscription.py index f01416a5a..b6cc523db 100644 --- a/plugins/modules/azure_rm_servicebustopicsubscription.py +++ b/plugins/modules/azure_rm_servicebustopicsubscription.py @@ -192,6 +192,7 @@ def __init__(self): ) super(AzureRMServiceSubscription, self).__init__(self.module_arg_spec, + supports_tags=False, supports_check_mode=True) def exec_module(self, **kwargs):