Skip to content

Commit

Permalink
Ignore comparing protected_settings (#580)
Browse files Browse the repository at this point in the history
* Ignore comparing protected_settings

* fix sanity error

* remove ignore mark

* correct vm extension idempotency; update no-longer-existing vm image

* add advanced tests for vm extension; update param to match sdk

* update small

Co-authored-by: Ross Bender <l3ender@users.noreply.github.com>
  • Loading branch information
Fred-sun and l3ender authored Feb 7, 2022
1 parent 725c77d commit 035d0cc
Show file tree
Hide file tree
Showing 12 changed files with 949 additions and 81 deletions.
18 changes: 9 additions & 9 deletions plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@
availability_set: avs-managed-disk
managed_disk_type: Standard_LRS
image:
offer: CoreOS
publisher: CoreOS
sku: Stable
offer: 0001-com-ubuntu-server-focal
publisher: canonical
sku: 20_04-lts-gen2
version: latest
vm_size: Standard_D4
Expand Down Expand Up @@ -477,9 +477,9 @@
- path: /home/adminUser/.ssh/authorized_keys
key_data: < insert your ssh public key here... >
image:
offer: CoreOS
publisher: CoreOS
sku: Stable
offer: 0001-com-ubuntu-server-focal
publisher: canonical
sku: 20_04-lts-gen2
version: latest
data_disks:
- lun: 0
Expand All @@ -504,9 +504,9 @@
boot_diagnostics:
enabled: yes
image:
offer: CoreOS
publisher: CoreOS
sku: Stable
offer: 0001-com-ubuntu-server-focal
publisher: canonical
sku: 20_04-lts-gen2
version: latest
data_disks:
- lun: 0
Expand Down
98 changes: 61 additions & 37 deletions plugins/modules/azure_rm_virtualmachineextension.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,63 @@
description:
- Name of a resource group where the vm extension exists or will be created.
required: true
type: str
name:
description:
- Name of the vm extension.
required: true
type: str
state:
description:
- State of the vm extension. Use C(present) to create or update a vm extension and C(absent) to delete a vm extension.
default: present
type: str
choices:
- absent
- present
location:
description:
- Valid Azure location. Defaults to location of the resource group.
type: str
virtual_machine_name:
description:
- The name of the virtual machine where the extension should be create or updated.
required: true
type: str
publisher:
description:
- The name of the extension handler publisher.
type: str
virtual_machine_extension_type:
description:
- The type of the extension handler.
type: str
type_handler_version:
description:
- The type version of the extension handler.
type: str
settings:
description:
- Json formatted public settings for the extension.
- JSON formatted public settings for the extension.
type: dict
protected_settings:
description:
- Json formatted protected settings for the extension.
- JSON formatted protected settings for the extension.
- >-
Previously configured settings are not available, so the parameter is not used for idempotency checks.
If changes to this parameter need to be applied, use in conjunction with I(force_update_tag).
type: dict
auto_upgrade_minor_version:
description:
- Whether the extension handler should be automatically upgraded across minor versions.
type: bool
force_update_tag:
description:
- Whether the extension should be updated or re-run even if no changes can be detected from what is currently configured.
- Helpful when applying changes to I(protected_settings).
type: bool
default: false
version_added: '1.10.0'
extends_documentation_fragment:
- azure.azcollection.azure
Expand All @@ -71,25 +92,24 @@
'''

EXAMPLES = '''
- name: Create VM Extension
azure_rm_virtualmachineextension:
name: myvmextension
location: eastus
resource_group: myResourceGroup
virtual_machine_name: myvm
publisher: Microsoft.Azure.Extensions
virtual_machine_extension_type: CustomScript
type_handler_version: 2.0
settings: '{"commandToExecute": "hostname"}'
auto_upgrade_minor_version: true
- name: Delete VM Extension
azure_rm_virtualmachineextension:
name: myvmextension
location: eastus
resource_group: myResourceGroup
virtual_machine_name: myvm
state: absent
- name: Create VM Extension
azure_rm_virtualmachineextension:
name: myvmextension
location: eastus
resource_group: myResourceGroup
virtual_machine_name: myvm
publisher: Microsoft.Azure.Extensions
virtual_machine_extension_type: CustomScript
type_handler_version: 2.0
settings: '{"commandToExecute": "hostname"}'
auto_upgrade_minor_version: true
- name: Delete VM Extension
azure_rm_virtualmachineextension:
name: myvmextension
resource_group: myResourceGroup
virtual_machine_name: myvm
state: absent
'''

RETURN = '''
Expand Down Expand Up @@ -157,7 +177,8 @@ def __init__(self):
type='str'
),
virtual_machine_name=dict(
type='str'
type='str',
required=True
),
publisher=dict(
type='str'
Expand All @@ -176,11 +197,16 @@ def __init__(self):
),
protected_settings=dict(
type='dict', no_log=True
)
),
force_update_tag=dict(
type='bool',
default=False
),
)

self.resource_group = None
self.name = None
self.virtual_machine_name = None
self.location = None
self.publisher = None
self.virtual_machine_extension_type = None
Expand All @@ -189,10 +215,10 @@ def __init__(self):
self.settings = None
self.protected_settings = None
self.state = None
self.force_update_tag = False

required_if = [
('state', 'present', [
'publisher', 'virtual_machine_extension_type', 'type_handler_version'])
('state', 'present', ['publisher', 'virtual_machine_extension_type', 'type_handler_version']),
]

self.results = dict(changed=False, state=dict())
Expand All @@ -212,32 +238,28 @@ def exec_module(self, **kwargs):
self.module.deprecate("The 'azure_rm_virtualmachine_extension' module has been renamed to 'azure_rm_virtualmachineextension'", version=(2, 9))

resource_group = None
response = None
to_be_updated = False

resource_group = self.get_resource_group(self.resource_group)
if not self.location:
self.location = resource_group.location

response = self.get_vmextension()

if self.state == 'present':
response = self.get_vmextension()
if not response:
to_be_updated = True
else:
if self.force_update_tag:
to_be_updated = True

if self.settings is not None:
if response['settings'] != self.settings:
response['settings'] = self.settings
to_be_updated = True
else:
self.settings = response['settings']

if self.protected_settings is not None:
if response['protected_settings'] != self.protected_settings:
response['protected_settings'] = self.protected_settings
to_be_updated = True
else:
self.protected_settings = response['protected_settings']

if response['location'] != self.location:
self.location = response['location']
self.module.warn("Property 'location' cannot be changed")
Expand Down Expand Up @@ -265,8 +287,9 @@ def exec_module(self, **kwargs):
self.results['changed'] = True
self.results['state'] = self.create_or_update_vmextension()
elif self.state == 'absent':
self.delete_vmextension()
self.results['changed'] = True
if response:
self.delete_vmextension()
self.results['changed'] = True

return self.results

Expand All @@ -284,7 +307,8 @@ def create_or_update_vmextension(self):
type_handler_version=self.type_handler_version,
auto_upgrade_minor_version=self.auto_upgrade_minor_version,
settings=self.settings,
protected_settings=self.protected_settings
protected_settings=self.protected_settings,
force_update_tag=self.force_update_tag,
)
poller = self.compute_client.virtual_machine_extensions.create_or_update(self.resource_group, self.virtual_machine_name, self.name, params)
response = self.get_poller_result(poller)
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/azure_rm_virtualmachineextension_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@
description:
- The name of the resource group.
required: True
type: str
virtual_machine_name:
description:
- The name of the virtual machine containing the extension.
required: True
type: str
name:
description:
- The name of the virtual machine extension.
type: str
tags:
description:
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
type: list
extends_documentation_fragment:
- azure.azcollection.azure
Expand Down
14 changes: 7 additions & 7 deletions plugins/modules/azure_rm_virtualmachinescaleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@
key_data: < insert your ssh public key here... >
managed_disk_type: Standard_LRS
image:
offer: CoreOS
publisher: CoreOS
sku: Stable
offer: 0001-com-ubuntu-server-focal
publisher: canonical
sku: 20_04-lts-gen2
version: latest
data_disks:
- lun: 0
Expand Down Expand Up @@ -475,10 +475,10 @@
}
],
"imageReference": {
"offer": "CoreOS",
"publisher": "CoreOS",
"sku": "Stable",
"version": "899.17.0"
"offer": "0001-com-ubuntu-server-focal",
"publisher": "canonical",
"sku": "20_04-lts-gen2",
"version": "20.04.202111210"
},
"osDisk": {
"caching": "ReadWrite",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"storageAccountName": "dummystorageaccount",
"storageAccountSasToken": "dummy-storage-sas-token",
"sinksConfig": {
"sink": [
{
"name": "TestEventHub",
"type": "EventHub",
"sasURL": "dummy-sas-url"
}
]
}
}
Loading

0 comments on commit 035d0cc

Please sign in to comment.