Skip to content

Commit

Permalink
feat(resource_dns_adlist): Add dns ad list support
Browse files Browse the repository at this point in the history
Closes #554
  • Loading branch information
vaerh committed Sep 19, 2024
1 parent 838345c commit b1ca164
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func Provider() *schema.Provider {
"routeros_firewall_mangle": ResourceIPFirewallMangle(),
"routeros_firewall_nat": ResourceIPFirewallNat(),
"routeros_dns": ResourceDns(),
"routeros_dns_adlist": ResourceDnsAdlist(),
"routeros_dns_record": ResourceDnsRecord(),

// Interface Objects
Expand Down
57 changes: 57 additions & 0 deletions routeros/resource_ip_dns_adlist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package routeros

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

/*
{
".id": "*1",
"disabled": "false",
"match-count": "0",
"name-count": "0",
"url": "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
}
*/

// ResourceDnsAdlist https://help.mikrotik.com/docs/display/ROS/DNS#DNS-Adlist
func ResourceDnsAdlist() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/dns/adlist"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields("match_count", "name_count"),

KeyDisabled: PropDisabledRw,
"file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to specify a local file path from which to read adlist data.",
ExactlyOneOf: []string{"file", "url"},
},
"ssl_verify": {
Type: schema.TypeBool,
Optional: true,
Description: "Specifies whether to validate the server's SSL certificate when connecting to an online " +
"resource. Will use the `/certificate` list to verify server validity.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"url": {
Type: schema.TypeString,
Optional: true,
Description: "Used to specify the URL of an adlist.",
ExactlyOneOf: []string{"file", "url"},
},
}

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: resSchema,
}
}
43 changes: 43 additions & 0 deletions routeros/resource_ip_dns_adlist_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package routeros

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testResourceDnsAdlist = "routeros_dns_adlist.test"

func TestAccResourceDnsAdlistTest_basic(t *testing.T) {
for _, name := range testNames {
t.Run(name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testSetTransportEnv(t, name)
},
ProviderFactories: testAccProviderFactories,
CheckDestroy: testCheckResourceDestroy("/ip/dns/adlist", "routeros_dns_adlist"),
Steps: []resource.TestStep{
{
Config: testAccResourceDnsAdlistConfig(),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testResourceDnsAdlist),
resource.TestCheckResourceAttr(testResourceDnsAdlist, "url", "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"),
resource.TestCheckResourceAttr(testResourceDnsAdlist, "ssl_verify", "false"),
),
},
},
})

})
}
}

func testAccResourceDnsAdlistConfig() string {
return providerConfig + `
resource "routeros_dns_adlist" "test" {
url = "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
ssl_verify = false
}`
}

0 comments on commit b1ca164

Please sign in to comment.