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

Support notes to azure_rm_lock.py #1097

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions plugins/modules/azure_rm_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
- Mutually exclusive with I(managed_resource_id).
- If neither I(managed_resource_id) or I(resource_group) are specified, manage a lock for the current subscription.
type: str
notes:
description:
- Notes about the lock. Maximum of 512 characters.
type: str
state:
description:
- State of the lock.
Expand Down Expand Up @@ -79,6 +83,7 @@
azure_rm_lock:
resource_group: myResourceGroup
name: myLock
notes: description_lock
level: read_only
- name: Create a lock for a subscription
Expand Down Expand Up @@ -113,6 +118,7 @@ def __init__(self):
state=dict(type='str', default='present', choices=['present', 'absent']),
resource_group=dict(type='str'),
managed_resource_id=dict(type='str'),
notes=dict(type='str'),
level=dict(type='str', choices=['can_not_delete', 'read_only'])
)

Expand All @@ -131,6 +137,7 @@ def __init__(self):
self.state = None
self.level = None
self.resource_group = None
self.note = None
self.managed_resource_id = None

super(AzureRMLock, self).__init__(self.module_arg_spec,
Expand All @@ -152,11 +159,17 @@ def exec_module(self, **kwargs):
lock_level = getattr(self.lock_models.LockLevel, self.level)
if not lock:
changed = True
lock = self.lock_models.ManagementLockObject(level=lock_level)
elif lock.level != lock_level:
self.log('Lock level changed')
lock.level = lock_level
changed = True
lock = self.lock_models.ManagementLockObject(level=lock_level, notes=self.notes)
else:
if lock.level != lock_level:
self.log('Lock level changed')
lock.level = lock_level
changed = True
if lock.notes != self.notes:
self.log('Lock notes changed')
lock.notes = self.notes
changed = True

if not self.check_mode:
lock = self.create_or_update_lock(scope, lock)
self.results['id'] = lock.id
Expand Down