-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resource_dns_adlist): Add dns ad list support
Closes #554
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}` | ||
} |