Skip to content

Commit

Permalink
fix srv
Browse files Browse the repository at this point in the history
  • Loading branch information
yec-akamai committed Jul 22, 2024
1 parent cd4d40b commit 63d9f65
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 26 deletions.
16 changes: 15 additions & 1 deletion docs/modules/domain_record.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ NOTE: Domain records are identified by their name, target, and type.
state: present
```
```yaml
- name: Create an SRV domain record
linode.cloud.domain_record:
domain: my-domain.com
service: srv-service
protocol: tcp
type: 'SRV'
target: host.example.com
port: 443
priority: 0
weight: 1
state: present
```
```yaml
- name: Delete a domain record
linode.cloud.domain_record:
Expand Down Expand Up @@ -53,7 +67,7 @@ NOTE: Domain records are identified by their name, target, and type.
| `domain_id` | <center>`int`</center> | <center>Optional</center> | The ID of the parent Domain. |
| `domain` | <center>`str`</center> | <center>Optional</center> | The name of the parent Domain. |
| `record_id` | <center>`int`</center> | <center>Optional</center> | The id of the record to modify. **(Conflicts With: `name`)** |
| `name` | <center>`str`</center> | <center>Optional</center> | The name of this Record. NOTE: If the name of the record ends with the domain, it will be dropped from the resulting record's name. **(Conflicts With: `record_id`)** |
| `name` | <center>`str`</center> | <center>Optional</center> | The name of this Record. NOTE: If the name of the record ends with the domain, it will be dropped from the resulting record's name. Unused for SRV record. Use the service property to set the service name for this record. **(Conflicts With: `record_id`)** |
| `port` | <center>`int`</center> | <center>Optional</center> | The port this Record points to. Only valid and required for SRV record requests. **(Updatable)** |
| `priority` | <center>`int`</center> | <center>Optional</center> | The priority of the target host for this Record. Lower values are preferred. Only valid for MX and SRV record requests. Required for SRV record requests. **(Updatable)** |
| `protocol` | <center>`str`</center> | <center>Optional</center> | The protocol this Record’s service communicates with. An underscore (_) is prepended automatically to the submitted value for this property. **(Updatable)** |
Expand Down
11 changes: 11 additions & 0 deletions plugins/module_utils/doc_fragments/domain_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
type: 'A'
target: '127.0.0.1'
state: present''', '''
- name: Create an SRV domain record
linode.cloud.domain_record:
domain: my-domain.com
service: srv-service
protocol: tcp
type: 'SRV'
target: host.example.com
port: 443
priority: 0
weight: 1
state: present''', '''
- name: Delete a domain record
linode.cloud.domain_record:
domain: my-domain.com
Expand Down
16 changes: 11 additions & 5 deletions plugins/modules/domain_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
description=[
"The name of this Record.",
"NOTE: If the name of the record ends with the domain, "
"it will be dropped from the resulting record's name.",
"it will be dropped from the resulting record's name. "
"Unused for SRV record. "
"Use the service property to set the service name for this record.",
],
),
"port": SpecField(
Expand Down Expand Up @@ -173,7 +175,7 @@ def __init__(self) -> None:
self.module_arg_spec = SPECDOC_META.ansible_spec
self.required_one_of: List[List[str]] = [
["domain", "domain_id"],
[("name", "type"), "record_id"],
["name", "record_id", "service"],
]
self.mutually_exclusive: List[List[str]] = [["name", "record_id"]]
self.results = {"changed": False, "actions": [], "record": None}
Expand All @@ -185,7 +187,6 @@ def __init__(self) -> None:
module_arg_spec=self.module_arg_spec,
required_one_of=self.required_one_of,
mutually_exclusive=self.mutually_exclusive,
required_together=self.required_together,
)

def _find_record(
Expand Down Expand Up @@ -266,10 +267,13 @@ def _create_record(self) -> Optional[DomainRecord]:
params = self.module.params
record_type = params.pop("type")
record_name = params.get("name")
record_service = params.get("service")

try:
self.register_action(
"Created domain record {0}".format(record_name)
"Created domain record type {0}: name is {1}; service is {2}".format(
record_type, record_name, record_service
)
)
return self._domain.record_create(record_type, **params)
except Exception as exception:
Expand Down Expand Up @@ -305,7 +309,9 @@ def _handle_present(self) -> None:
"record with id {0} does not exist".format(record_id)
)

if self._record is None and record_name is not None:
if self._record is None and (
record_name is not None or params.get("service") is not None
):
self._record = self._create_record()

self._update_record()
Expand Down
53 changes: 33 additions & 20 deletions tests/integration/targets/domain_record/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,6 @@
- record_create.record.ttl_sec == 3600
- record_create.record.weight == 55

- name: Create a Service records
linode.cloud.domain_record:
domain: '{{ domain_create.domain.domain }}'
state: present
service: carddavs
protocol: tcp
type: "SRV"
target: host.example.com
port: 443
priority: 0
weight: 1
register: srv_create

- name: Assert SRV record is created
assert:
that:
- srv_create.record.type == 'SRV'

- name: Update domain_record
linode.cloud.domain_record:
domain: '{{ domain_create.domain.domain }}'
Expand Down Expand Up @@ -164,6 +146,24 @@
- record_dupe_update.record.ttl_sec == 300
- record_dupe_update.record.weight == 55

- name: Create an SRV domain record
linode.cloud.domain_record:
domain: '{{ domain_create.domain.domain }}'
service: carddavs
protocol: tcp
type: "SRV"
target: host.example.com
port: 443
priority: 0
weight: 1
state: present
register: srv_create

- name: Assert SRV record is created
assert:
that:
- srv_create.record.type == 'SRV'

- name: Get domain_info
linode.cloud.domain_info:
domain: '{{ domain_create.domain.domain }}'
Expand All @@ -172,7 +172,7 @@
- name: Assert domain_info response
assert:
that:
- domain_info.records|length == 3
- domain_info.records|length == 4

- name: Create domain_record containing FQDN
linode.cloud.domain_record:
Expand Down Expand Up @@ -261,7 +261,20 @@
assert:
that:
- record_dupe_delete.changed
- record_dupe_delete.record.id == record_dupe_delete.record.id
- record_dupe_delete.record.id == record_dupe_create.record.id

- name: Delete SRV domain_record
linode.cloud.domain_record:
domain: '{{ domain_create.domain.domain }}'
record_id: '{{ srv_create.record.id }}'
state: absent
register: srv_record_delete

- name: Assert SRV domain_record is deleted
assert:
that:
- srv_record_delete.changed
- srv_record_delete.record.id == srv_create.record.id

- name: Delete domain
linode.cloud.domain:
Expand Down

0 comments on commit 63d9f65

Please sign in to comment.