-
Notifications
You must be signed in to change notification settings - Fork 334
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
azure_rm_virtualmachine: better support for User Assigned and System Assigned identities #1177
Conversation
…ties First version, still not complete. Working: * change UserAssigned for SystemAssigned * add UserAssigned to SystemAssigned * Remove SystemAssigned and leave UserAssigned
* Tested None vm_identity (remove identity) * Checks pressence of 'user_assigned_identities' when UserAssigned 'type' is used
* user_assigned_identities has two fields: id (list) and append (bool) * you can append new managed identities to existing with append=True * you can add SystemAssigned without removing current appended UserAssigned
Tasks to do * Review and clean up * Add comments * Leave test main.yaml as it was * Modify inventory to use a custom subnet
* Commented code * Removed self.log sentences * Set options defaults * hosts of tests of azure_rm_virtualmachine changed back to 'all'
I have found out that the user managed identities can be created during the tests using |
@cpiment Please! Thanks you very much! |
Co-authored-by: Fred-sun <[email protected]>
@Fred-sun I have just commited your changes, thank you so much! |
elif 'UserAssigned' in self.vm_identity.get('type') and len(self.vm_identity.get('user_assigned_identities',{}).get('id',[])) == 0: | ||
# Fail if append is False | ||
if vm_identity_user_assigned_append is False: | ||
self.fail("UserAssigned specified but no User Assigned IDs provided and no UserAssigned identities are currently assigned to the VM") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too long (165 characters)
self.fail("UserAssigned specified but no User Assigned IDs provided and no UserAssigned identities are currently assigned to the VM") | |
self.fail("UserAssigned specified but no User Assigned IDs provided and no UserAssigned identities are currently assigned to the VM") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have divided this line in two. Do you need me to rephrase the error message? If code reaches this point, the module arguments specify that a User Assigned Managed Identity has to be appended to the VM, but there aren't identities in the module arguments nor in the current VM configuration
# Fail if append is False | ||
if vm_identity_user_assigned_append is False: | ||
self.fail("UserAssigned specified but no User Assigned IDs provided and no UserAssigned identities are currently assigned to the VM") | ||
# If append is true, user is changing from 'UserAssigned' to 'SystemAssigned, UserAssigned' and wants to keep current UserAssigned identities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too long (169 characters)
# If append is true, user is changing from 'UserAssigned' to 'SystemAssigned, UserAssigned' and wants to keep current UserAssigned identities | |
# If append is true, user is changing from 'UserAssigned' to 'SystemAssigned, UserAssigned' and wants to keep current UserAssigned identities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have divided this line in two
Code style changes Co-authored-by: Fred-sun <[email protected]>
@@ -1813,6 +1897,49 @@ def exec_module(self, **kwargs): | |||
if self.license_type is not None: | |||
vm_resource.license_type = self.license_type | |||
|
|||
if self.vm_identity is not None: | |||
# If 'append' is set to True save current user assigned managed identities to use later | |||
if self.vm_identity.get('user_assigned_identities', {}) is not None and self.vm_identity.get('user_assigned_identities', {}).get('append', False) is True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (178 > 160 characters)
if self.vm_identity.get('user_assigned_identities', {}) is not None and self.vm_identity.get('user_assigned_identities', {}).get('append', False) is True: | |
if self.vm_identity.get('user_assigned_identities', {}) is not None and self.vm_identity.get('user_assigned_identities', {}).get('append', False) is True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have splitted this line in two
Co-authored-by: Fred-sun <[email protected]>
Hi @Fred-sun Is there anything else to review? Thanks! |
@cpiment Perfact! I will push for merged! Thank you very much! |
@cpiment LGTM |
SUMMARY
Allows to set/unset User and System managed identities to Virtual Machines
Fixes #1173
ISSUE TYPE
COMPONENT NAME
azure_rm_virtualmachine
ADDITIONAL INFORMATION
Before
Now