Skip to content

Commit

Permalink
fix: /ip/dns/static errors when trying to change the resource type
Browse files Browse the repository at this point in the history
Fixes #156
  • Loading branch information
vaerh committed Mar 11, 2023
1 parent a6f307c commit 0a935cd
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 46 deletions.
68 changes: 64 additions & 4 deletions docs/resources/ip_dns_record.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,81 @@ resource "routeros_ip_dns_record" "regexp_record" {
regexp = ".*pool.ntp.org"
address = "192.168.88.1"
}
resource "routeros_dns_record" "aaaa_record" {
name = "ipv6.lan"
address = "ff00::1"
type = "AAAA"
}
resource "routeros_dns_record" "cname_record" {
name = "cname.lan"
cname = "ipv4.lan"
type = "CNAME"
}
resource "routeros_dns_record" "fwd_record" {
name = "fwd.lan"
forward_to = "127.0.0.1"
type = "FWD"
}
resource "routeros_dns_record" "mx_record" {
name = "mx.lan"
mx_exchange = "127.0.0.1"
mx_preference = 10
type = "MX"
}
resource "routeros_dns_record" "ns_record" {
name = "ns.lan"
ns = "127.0.0.1"
type = "NS"
}
resource "routeros_dns_record" "nxdomain_record" {
name = "nxdomain.lan"
type = "NXDOMAIN"
}
resource "routeros_dns_record" "srv_record" {
name = "srv.lan"
srv_port = 8080
srv_priority = 10
srv_target = "127.0.0.1"
srv_weight = 100
type = "SRV"
}
resource "routeros_dns_record" "txt_record" {
name = "_acme-challenge.yourwebsite.com"
text = "dW6MrI3nBy3eJgYWH3QAg1Cwk_TvjFESOuKo+mp6nm1"
type = "TXT"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `address` (String) The A record to be returend from the DNS hostname.

### Optional

- `address` (String) The A record to be returend from the DNS hostname.
- `address_list` (String) Name of the Firewall address list to which address must be dynamically added when some request matches the entry.
- `cname` (String) Alias name for a domain name.
- `comment` (String)
- `disabled` (Boolean)
- `forward_to` (String) The IP address of a domain name server to which a particular DNS request must be forwarded.
- `match_subdomain` (Boolean) Whether the record will match requests for subdomains.
- `mx_exchange` (String) The domain name of the MX server.
- `mx_preference` (Number) Preference of the particular MX record.
- `name` (String) The name of the DNS hostname to be created.
- `ns` (String) Name of the authoritative domain name server for the particular record.
- `regexp` (String) DNS regexp. Regexp entries are case sensitive, but since DNS requests are not case sensitive, RouterOS converts DNS names to lowercase, you should write regex only with lowercase letters.
- `srv_port` (Number) The TCP or UDP port on which the service is to be found.
- `srv_priority` (Number) Priority of the particular SRV record.
- `srv_target` (String) The canonical hostname of the machine providing the service ends in a dot.
- `srv_weight` (String) Weight of the particular SRC record.
- `text` (String) Textual information about the domain name.
- `ttl` (String) The ttl of the DNS record.
- `type` (String) Type of the DNS record. Available values are: A, AAAA, CNAME, FWD, MX, NS, NXDOMAIN, SRV, TXT

Expand Down
53 changes: 52 additions & 1 deletion examples/resources/routeros_ip_dns_record/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,55 @@ resource "routeros_ip_dns_record" "name_record" {
resource "routeros_ip_dns_record" "regexp_record" {
regexp = ".*pool.ntp.org"
address = "192.168.88.1"
}
}

resource "routeros_dns_record" "aaaa_record" {
name = "ipv6.lan"
address = "ff00::1"
type = "AAAA"
}

resource "routeros_dns_record" "cname_record" {
name = "cname.lan"
cname = "ipv4.lan"
type = "CNAME"
}

resource "routeros_dns_record" "fwd_record" {
name = "fwd.lan"
forward_to = "127.0.0.1"
type = "FWD"
}

resource "routeros_dns_record" "mx_record" {
name = "mx.lan"
mx_exchange = "127.0.0.1"
mx_preference = 10
type = "MX"
}

resource "routeros_dns_record" "ns_record" {
name = "ns.lan"
ns = "127.0.0.1"
type = "NS"
}

resource "routeros_dns_record" "nxdomain_record" {
name = "nxdomain.lan"
type = "NXDOMAIN"
}

resource "routeros_dns_record" "srv_record" {
name = "srv.lan"
srv_port = 8080
srv_priority = 10
srv_target = "127.0.0.1"
srv_weight = 100
type = "SRV"
}

resource "routeros_dns_record" "txt_record" {
name = "_acme-challenge.yourwebsite.com"
text = "dW6MrI3nBy3eJgYWH3QAg1Cwk_TvjFESOuKo+mp6nm1"
type = "TXT"
}
144 changes: 114 additions & 30 deletions routeros/resource_ip_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,144 @@ import (
)

/*
{
".id": "*1",
"address": "192.168.88.1",
"comment": "defconf",
"disabled": "false",
"dynamic": "false",
"name": "router.lan",
"ttl": "1d"
},
{
".id": "*2",
"address": "2001:db8:1000::1",
"disabled": "false",
"dynamic": "false",
"name": "ipv6.example.com",
"ttl": "1d",
"type": "AAAA"}
{
".id": "*9",
"address": "192.168.88.1",
"disabled": "false",
"dynamic": "false",
"regexp": ".*pool.ntp.org",
"ttl": "1d"
{ { {
".id": "*3", ".id": "*5", ".id": "*4",
"address": "127.0.0.1", "address": "ff00::1", "cname": "ipv4",
"address-list": "subdomain", "disabled": "false", "disabled": "false",
"disabled": "false", "dynamic": "false", "dynamic": "false",
"dynamic": "false", "name": "ipv6", "name": "cname",
"match-subdomain": "true", "ttl": "1d", "ttl": "1d",
"name": "ipv4", "type": "AAAA" "type": "CNAME"
"ttl": "1d" }, },
},
{ { {
".id": "*6", ".id": "*7", ".id": "*8",
"disabled": "false", "disabled": "true", "disabled": "false",
"dynamic": "false", "dynamic": "false", "dynamic": "false",
"forward-to": "127.0.0.1", "mx-exchange": "127.0.0.1", "name": "ns",
"name": "fwd", "mx-preference": "10", "ns": "127.0.0.1",
"ttl": "1d", "name": "mx", "ttl": "1d",
"type": "FWD" "ttl": "1d", "type": "NS"
}, "type": "MX" },
},
{ { {
".id": "*9", ".id": "*A", ".id": "*B",
"disabled": "false", "disabled": "false", "disabled": "false",
"dynamic": "false", "dynamic": "false", "dynamic": "false",
"name": "nxdomain", "name": "srv", "name": "txt",
"ttl": "1d", "srv-port": "8080", "text": "DNSSEC",
"type": "NXDOMAIN" "srv-priority": "10", "ttl": "1d",
}, "srv-target": "127.0.0.1", "type": "TXT"
"srv-weight": "100", }
"ttl": "1d",
"type": "SRV"
},
*/

// ResourceDnsRecord https://wiki.mikrotik.com/wiki/Manual:IP/DNS
// ResourceDnsRecord https://wiki.mikrotik.com/wiki/Manual:IP/DNS https://help.mikrotik.com/docs/display/ROS/DNS
func ResourceDnsRecord() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/dns/static"),
MetaId: PropId(Id),

"address": {
Type: schema.TypeString,
Required: true,
Description: "The A record to be returend from the DNS hostname.",
Type: schema.TypeString,
Optional: true,
Description: "The A record to be returend from the DNS hostname.",
ConflictsWith: []string{"cname", "forward_to", "mx_exchange", "ns", "srv_target", "text"},
},
"address_list": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the Firewall address list to which address must be dynamically added when some " +
"request matches the entry.",
},
KeyComment: PropCommentRw,
"cname": {
Type: schema.TypeString,
Optional: true,
Description: "Alias name for a domain name.",
ConflictsWith: []string{"address", "forward_to", "mx_exchange", "ns", "srv_target", "text"},
},
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
KeyDynamic: PropDynamicRo,
"forward_to": {
Type: schema.TypeString,
Optional: true,
Description: "The IP address of a domain name server to which a particular DNS request must be forwarded.",
ConflictsWith: []string{"address", "cname", "mx_exchange", "ns", "srv_target", "text"},
},
"match_subdomain": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether the record will match requests for subdomains.",
},
"mx_exchange": {
Type: schema.TypeString,
Optional: true,
Description: "The domain name of the MX server.",
ConflictsWith: []string{"address", "cname", "forward_to", "ns", "srv_target", "text"},
},
"mx_preference": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Preference of the particular MX record.",
RequiredWith: []string{"mx_exchange"},
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the DNS hostname to be created.",
ExactlyOneOf: []string{"name", "regexp"},
},
"ns": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the authoritative domain name server for the particular record.",
ConflictsWith: []string{"address", "cname", "forward_to", "mx_exchange", "srv_target", "text"},
},
"regexp": {
Type: schema.TypeString,
Optional: true,
Description: "DNS regexp. Regexp entries are case sensitive, but since DNS requests are not case sensitive, " +
"RouterOS converts DNS names to lowercase, you should write regex only with lowercase letters.",
ExactlyOneOf: []string{"name", "regexp"},
},
"srv_port": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The TCP or UDP port on which the service is to be found.",
ValidateFunc: validation.IntBetween(0, 65535),
RequiredWith: []string{"srv_target"},
},
"srv_priority": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Priority of the particular SRV record.",
RequiredWith: []string{"srv_target"},
},
"srv_target": {
Type: schema.TypeString,
Optional: true,
Description: "The canonical hostname of the machine providing the service ends in a dot.",
ConflictsWith: []string{"address", "cname", "forward_to", "mx_exchange", "ns", "text"},
},
"srv_weight": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Weight of the particular SRC record.",
RequiredWith: []string{"srv_target"},
},
"text": {
Type: schema.TypeString,
Optional: true,
Description: "Textual information about the domain name.",
ConflictsWith: []string{"address", "cname", "forward_to", "mx_exchange", "ns", "srv_target"},
},
"ttl": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -72,7 +156,7 @@ func ResourceDnsRecord() *schema.Resource {
Computed: true,
Description: "Type of the DNS record. Available values are: A, AAAA, CNAME, FWD, MX, NS, NXDOMAIN, SRV, TXT",
ValidateFunc: validation.StringInSlice([]string{"A", "AAAA", "CNAME", "FWD", "MX", "NS", "NXDOMAIN",
"SRV", "TXT "}, false),
"SRV", "TXT"}, false),
},
}
return &schema.Resource{
Expand Down
Loading

0 comments on commit 0a935cd

Please sign in to comment.