From 0c1316c2598bafa3826935171124c7e536197e29 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 8 Oct 2024 21:40:20 +0800 Subject: [PATCH 1/3] Add support 'is_authentication_with_ssh_key' to azure_rm_devtestlabvirtualmachine.py --- .../azure_rm_devtestlabvirtualmachine.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_devtestlabvirtualmachine.py b/plugins/modules/azure_rm_devtestlabvirtualmachine.py index 1498a5dde..aa8a9b429 100644 --- a/plugins/modules/azure_rm_devtestlabvirtualmachine.py +++ b/plugins/modules/azure_rm_devtestlabvirtualmachine.py @@ -140,6 +140,11 @@ choices: - standard - premium + is_authentication_with_ssh_key: + description: + - Indicates whether this virtual machine uses an SSH key for authentication. + - I(is_authentication_with_ssh_key=True) when I(ssh_key) is set for ssh authentication. + type: bool state: description: - Assert the state of the Virtual Machine. @@ -322,6 +327,9 @@ def __init__(self): type='str', choices=['standard', 'premium'] ), + is_authentication_with_ssh_key=dict( + type='bool' + ), state=dict( type='str', default='present', @@ -330,8 +338,8 @@ def __init__(self): ) required_if = [ - ('state', 'present', [ - 'image', 'lab_subnet', 'vm_size', 'os_type']) + ('state', 'present', ['image', 'lab_subnet', 'vm_size', 'os_type']), + ('ssh_key', '*', ['is_authentication_with_ssh_key']) ] self.resource_group = None @@ -431,6 +439,12 @@ def exec_module(self, **kwargs): if len(self.lab_virtual_machine.get('artifacts', [])) != old_response['artifact_deployment_status']['total_artifacts']: self.module.warn("Property 'artifacts' cannot be changed") + if self.lab_virtual_machine.get('is_authentication_with_ssh_key') is not None: + if bool(old_response['is_authentication_with_ssh_key']) != bool(self.lab_virtual_machine['is_authentication_with_ssh_key']): + self.module.warn("Property 'is_authentication_with_ssh_key' cannot be changed") + else: + self.lab_virtual_machine['is_authentication_with_ssh_key'] = old_response['is_authentication_with_ssh_key'] + if self.lab_virtual_machine.get('disallow_public_ip_address') is not None: if old_response['disallow_public_ip_address'] != self.lab_virtual_machine.get('disallow_public_ip_address'): self.module.warn("Property 'disallow_public_ip_address' cannot be changed") From bc7a7b28622ecdab5a7c754b1f6101b7f4191bef Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 8 Oct 2024 21:42:48 +0800 Subject: [PATCH 2/3] Update azure_rm_devtestlabvirtualmachine_info.py --- .../modules/azure_rm_devtestlabvirtualmachine_info.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_devtestlabvirtualmachine_info.py b/plugins/modules/azure_rm_devtestlabvirtualmachine_info.py index 8a3692e2a..1a833a08c 100644 --- a/plugins/modules/azure_rm_devtestlabvirtualmachine_info.py +++ b/plugins/modules/azure_rm_devtestlabvirtualmachine_info.py @@ -87,6 +87,12 @@ returned: always type: str sample: myVm + is_authentication_with_ssh_key: + description: + - Indicates whether this virtual machine uses an SSH key for authentication. + type: bool + returned: always + sample: False notes: description: - Notes of the virtual machine. @@ -314,7 +320,8 @@ def format_response(self, item): 'compute_vm_name': self.parse_resource_to_dict(d.get('compute_id')).get('name'), 'fqdn': d.get('fqdn'), 'provisioning_state': d.get('provisioning_state'), - 'tags': d.get('tags', None) + 'tags': d.get('tags', None), + 'is_authentication_with_ssh_key': d.get('is_authentication_with_ssh_key') } return d From e83c1588c0b51b387d1445439c5962b2b4f49eb2 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 8 Oct 2024 23:48:30 +0800 Subject: [PATCH 3/3] Add constraint --- plugins/modules/azure_rm_devtestlabvirtualmachine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_devtestlabvirtualmachine.py b/plugins/modules/azure_rm_devtestlabvirtualmachine.py index aa8a9b429..0cda981de 100644 --- a/plugins/modules/azure_rm_devtestlabvirtualmachine.py +++ b/plugins/modules/azure_rm_devtestlabvirtualmachine.py @@ -339,7 +339,7 @@ def __init__(self): required_if = [ ('state', 'present', ['image', 'lab_subnet', 'vm_size', 'os_type']), - ('ssh_key', '*', ['is_authentication_with_ssh_key']) + ('is_authentication_with_ssh_key', True, ['ssh_key']) ] self.resource_group = None