diff --git a/routeros/provider.go b/routeros/provider.go index 3abb0141..d4a75281 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -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 diff --git a/routeros/resource_ip_dns_adlist.go b/routeros/resource_ip_dns_adlist.go new file mode 100644 index 00000000..5e597a4b --- /dev/null +++ b/routeros/resource_ip_dns_adlist.go @@ -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, + } +} diff --git a/routeros/resource_ip_dns_adlist_test.go b/routeros/resource_ip_dns_adlist_test.go new file mode 100644 index 00000000..b0d6b1df --- /dev/null +++ b/routeros/resource_ip_dns_adlist_test.go @@ -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 +}` +}