Skip to content

Commit

Permalink
Add tags for azure_rm_loganalyticsworkspace (#434)
Browse files Browse the repository at this point in the history
* add tags for azure_rm_loganalyticsworkspace

* Add update function for this module
  • Loading branch information
Fred-sun authored Mar 4, 2021
1 parent 89e8add commit 2531320
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
16 changes: 15 additions & 1 deletion plugins/modules/azure_rm_loganalyticsworkspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,23 @@ def exec_module(self, **kwargs):
changed = True
workspace = self.log_analytics_models.Workspace(sku=self.log_analytics_models.WorkspaceSku(name=self.sku),
retention_in_days=self.retention_in_days,
location=self.location)
location=self.location,
tags=self.tags)
if not self.check_mode:
workspace = self.create_workspace(workspace)
elif workspace and self.state == 'present':
if workspace.retention_in_days != self.retention_in_days:
changed = True
results = dict()
update_tags, results['tags'] = self.update_tags(workspace.tags)
if update_tags:
changed = True
if not self.check_mode and changed:
workspace = self.log_analytics_models.Workspace(sku=self.log_analytics_models.WorkspaceSku(name=self.sku),
retention_in_days=self.retention_in_days,
location=self.location,
tags=results['tags'])
workspace = self.create_workspace(workspace)
elif workspace and self.state == 'absent':
changed = True
workspace = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- name: Prepare random number
set_fact:
name: "loganalytics{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
retention_days: 30
retention_days: 60

- name: Create Log Analytics Workspace (Check Mode On)
azure_rm_loganalyticsworkspace:
Expand Down Expand Up @@ -38,17 +38,39 @@
intelligence_packs:
Backup: true
Containers: true
retention_in_days: "{{ retention_days }}"
retention_in_days: 30
resource_group: "{{ resource_group }}"
tags:
key1: value1
register: output

- assert:
that:
- output.changed
- output.retention_in_days == retention_days
- output.retention_in_days == 30
# - output.intelligence_packs | json_query('[?name == `Backup`].enabled') | first == true
# - output.intelligence_packs | json_query('[?name == `Containers`].enabled') | first == true
- output.sku == 'pergb2018'
- output.tags.key1 == 'value1'

- name: Update Log Analytics Workspace
azure_rm_loganalyticsworkspace:
name: "{{ name }}"
intelligence_packs:
Backup: true
Containers: true
retention_in_days: "{{ retention_days }}"
resource_group: "{{ resource_group }}"
tags:
key1: value1
key2: value2
register: output

- assert:
that:
- output.changed
- output.retention_in_days == retention_days
- output.tags.key2 == 'value2'

- name: Get Log Analytics workspace information (Show full information)
azure_rm_loganalyticsworkspace_info:
Expand Down

0 comments on commit 2531320

Please sign in to comment.