Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tags option to azure_rm_resource_info module #1498

Merged
merged 7 commits into from
Mar 20, 2024
24 changes: 23 additions & 1 deletion plugins/modules/azure_rm_resource_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
description:
- Subresource name.
type: str
tags:
valkiriaaquatica marked this conversation as resolved.
Show resolved Hide resolved
description:
- A dictionary of tags to filter on.
- Each key-value pair in the dictionary specifies a tag name and its value to filter on differente resources.
type: dict
required: false
valkiriaaquatica marked this conversation as resolved.
Show resolved Hide resolved
default: {}

extends_documentation_fragment:
- azure.azcollection.azure
Expand All @@ -98,6 +105,14 @@
azure_rm_resource_info:
resource_group: "{{ resource_group }}"
resource_type: resources

- name: Get all snapshots of all resource groups of a subscription but filtering with two tags.
azure_rm_resource_info:
provider: compute
resource_type: snapshots
tags:
enviroment: dev
department: hr
'''

RETURN = '''
Expand Down Expand Up @@ -346,7 +361,8 @@ def __init__(self):
),
api_version=dict(
type='str'
)
),
tags=dict(type='dict', default={})
)
# store the results of the module operation
self.results = dict(
Expand Down Expand Up @@ -449,6 +465,12 @@ def exec_module(self, **kwargs):
self.fail('Failed to parse response: ' + str(e))
if not skiptoken:
break
if kwargs['tags']:
filtered_response = []
for resource in self.results['response']:
if all(resource.get('tags', {}).get(tag_key) == tag_value for tag_key, tag_value in kwargs['tags'].items()):
filtered_response.append(resource)
self.results['response'] = filtered_response
return self.results


Expand Down