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

linode.cloud.domain_record: Account for API removal of '.' suffix from target #653

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions plugins/modules/domain_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,15 @@ def _find_record(
self, domain: Domain, name: str, rtype: str, target: str
) -> Optional[DomainRecord]:
# We should strip the FQDN from the user-defined record name if defined.
suffix = "." + domain.domain
search_name = name
if search_name.endswith(suffix):
search_name = search_name[: -len(suffix)]
name = name.removesuffix("." + domain.domain)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use .removesuffix(...) here now that Python 3.9 is our minimum supported version.


# The Linode API will implicitly strip the `.` suffix from returned targets
target = target.removesuffix(".")

try:
for record in domain.records:
if (
record.name == search_name
record.name == name
and record.type == rtype
and record.target == target
):
Expand Down
32 changes: 32 additions & 0 deletions tests/integration/targets/domain_record/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,38 @@
- record_fqdn_delete.record.name == 'fqdn'
- record_fqdn_delete.changed

- name: Create a CNAME record with a '.'-suffixed target
linode.cloud.domain_record:
domain: '{{ domain_create.domain.domain }}'
name: 'cname.{{ domain_create.domain.domain }}'
type: CNAME
target: 'foo.{{ domain_create.domain.domain }}.'
state: present
register: record_cname

- name: Assert the CNAME record was successfully created
assert:
that:
- record_cname.changed
- record_cname.record.name == 'cname'
- record_cname.record.type == 'CNAME'
- record_cname.record.target == 'foo.' + domain_create.domain.domain

- name: Delete the CNAME record
linode.cloud.domain_record:
domain: '{{ domain_create.domain.domain }}'
name: 'cname.{{ domain_create.domain.domain }}'
type: CNAME
target: 'foo.{{ domain_create.domain.domain }}.'
state: absent
register: record_cname_delete

- name: Assert the CNAME record was deleted
assert:
that:
- record_cname_delete.record.name == 'cname'
- record_cname_delete.changed

always:
- ignore_errors: yes
block:
Expand Down
Loading