1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-03 23:51:48 +00:00

fix: zone rrset idempotency (#737)

##### SUMMARY

- The order of dns records is not guaranteed, this ensure the module is
idempotent.
- The API defaults to an empty string when comments are not set, ensure
the module is idempotent when no comments are given.

##### ISSUE TYPE

- Bugfix

Closes #740
This commit is contained in:
Jonas L. 2025-11-17 14:45:04 +01:00 committed by GitHub
parent f87c23629b
commit 79f78fae28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 9 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- zone_rrset - Records order is not guaranteed, the module will not generate a diff if the order of records changes.
- zone_rrset - Records without comments will not generate a diff anymore.

View file

@ -199,7 +199,7 @@ class AnsibleHCloudZoneRRSet(AnsibleHCloud):
def _prepare_result_record(self, record: ZoneRecord): def _prepare_result_record(self, record: ZoneRecord):
return { return {
"value": record.value, "value": record.value,
"comment": record.comment, "comment": record.comment or "", # API defaults to "", this ensure idempotency
} }
def _get(self): def _get(self):
@ -321,6 +321,9 @@ class AnsibleHCloudZoneRRSet(AnsibleHCloud):
current = [self._prepare_result_record(o) for o in self.hcloud_zone_rrset.records] current = [self._prepare_result_record(o) for o in self.hcloud_zone_rrset.records]
wanted = [self._prepare_result_record(ZoneRecord.from_dict(o)) for o in self.module.params.get("records")] wanted = [self._prepare_result_record(ZoneRecord.from_dict(o)) for o in self.module.params.get("records")]
current = sorted(current, key=lambda x: x["value"])
wanted = sorted(wanted, key=lambda x: x["value"])
return current != wanted return current != wanted
def present(self): def present(self):

View file

@ -154,7 +154,7 @@ class AnsibleHCloudZoneRRSetInfo(AnsibleHCloud):
def _prepare_result_record(self, record: ZoneRecord): def _prepare_result_record(self, record: ZoneRecord):
return { return {
"value": record.value, "value": record.value,
"comment": record.comment, "comment": record.comment or "",
} }
def get_zone_rrsets(self): def get_zone_rrsets(self):

View file

@ -91,6 +91,7 @@
key: changed key: changed
new: value new: value
records: records:
- value: 201.118.10.10 # No comment
- value: 201.118.10.11 - value: 201.118.10.11
comment: web server 1 comment: web server 1
- value: 201.118.10.13 - value: 201.118.10.13
@ -107,11 +108,13 @@
- result.hcloud_zone_rrset.labels.key == "changed" - result.hcloud_zone_rrset.labels.key == "changed"
- result.hcloud_zone_rrset.labels.new == "value" - result.hcloud_zone_rrset.labels.new == "value"
- result.hcloud_zone_rrset.change_protection == true - result.hcloud_zone_rrset.change_protection == true
- result.hcloud_zone_rrset.records | count == 2 - result.hcloud_zone_rrset.records | count == 3
- result.hcloud_zone_rrset.records[0].value == "201.118.10.11" - result.hcloud_zone_rrset.records[0].value == "201.118.10.10"
- result.hcloud_zone_rrset.records[0].comment == "web server 1" - result.hcloud_zone_rrset.records[0].comment == ""
- result.hcloud_zone_rrset.records[1].value == "201.118.10.13" - result.hcloud_zone_rrset.records[1].value == "201.118.10.11"
- result.hcloud_zone_rrset.records[1].comment == "web server 3" - result.hcloud_zone_rrset.records[1].comment == "web server 1"
- result.hcloud_zone_rrset.records[2].value == "201.118.10.13"
- result.hcloud_zone_rrset.records[2].comment == "web server 3"
- name: Test update idempotency - name: Test update idempotency
hetzner.hcloud.zone_rrset: hetzner.hcloud.zone_rrset:
@ -123,10 +126,12 @@
key: changed key: changed
new: value new: value
records: records:
- value: 201.118.10.11 - value: 201.118.10.10 # No comment
comment: web server 1 # Order is not guaranteed, should still be idempotent
- value: 201.118.10.13 - value: 201.118.10.13
comment: web server 3 comment: web server 3
- value: 201.118.10.11
comment: web server 1
change_protection: true change_protection: true
register: result register: result
- name: Verify update idempotency - name: Verify update idempotency