Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dns_adlist): Change an invalid resource name. #558

Merged
merged 17 commits into from
Sep 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(hotspot): Add new resource routeros_ip_hotspot_walled_garden
vaerh committed Sep 24, 2024
commit 9c111eeefa0ce90e0bc2f02c9c2d9a4794487cbe
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/ip/hotspot/walled-garden get [print show-ids]]
terraform import routeros_ip_hotspot_walled_garden.test *3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "routeros_ip_hotspot_walled_garden" "test" {
action = "deny"
dst_host = "1.2.3.4"
dst_port = "!443"
}
11 changes: 6 additions & 5 deletions routeros/provider.go
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ func Provider() *schema.Provider {
ResourcesMap: map[string]*schema.Resource{

// IP objects
"routeros_ip_address": ResourceIPAddress(),
"routeros_ip_dhcp_client": ResourceDhcpClient(),
"routeros_ip_dhcp_client_option": ResourceDhcpClientOption(),
"routeros_ip_dhcp_relay": ResourceDhcpRelay(),
@@ -89,20 +90,20 @@ func Provider() *schema.Provider {
"routeros_ip_dhcp_server_lease": ResourceDhcpServerLease(),
"routeros_ip_dhcp_server_option": ResourceDhcpServerOption(),
"routeros_ip_dhcp_server_option_set": ResourceDhcpServerOptionSet(),
"routeros_ip_dns": ResourceDns(),
"routeros_ip_dns_adlist": ResourceDnsAdlist(),
"routeros_ip_dns_record": ResourceDnsRecord(),
"routeros_ip_firewall_addr_list": ResourceIPFirewallAddrList(),
"routeros_ip_firewall_connection_tracking": ResourceIPConnectionTracking(),
"routeros_ip_firewall_filter": ResourceIPFirewallFilter(),
"routeros_ip_firewall_mangle": ResourceIPFirewallMangle(),
"routeros_ip_firewall_nat": ResourceIPFirewallNat(),
"routeros_ip_firewall_raw": ResourceIPFirewallRaw(),
"routeros_ip_address": ResourceIPAddress(),
"routeros_ip_hotspot_walled_garden": ResourceIpHotspotWalledGarden(),
"routeros_ip_neighbor_discovery_settings": ResourceIpNeighborDiscoverySettings(),
"routeros_ip_pool": ResourceIPPool(),
"routeros_ip_route": ResourceIPRoute(),
"routeros_ip_dns": ResourceDns(),
"routeros_ip_dns_adlist": ResourceDnsAdlist(),
"routeros_ip_dns_record": ResourceDnsRecord(),
"routeros_ip_service": ResourceIpService(),
"routeros_ip_neighbor_discovery_settings": ResourceIpNeighborDiscoverySettings(),
"routeros_ip_ssh_server": ResourceIpSSHServer(),
"routeros_ip_upnp": ResourceUPNPSettings(),
"routeros_ip_upnp_interfaces": ResourceUPNPInterfaces(),
86 changes: 86 additions & 0 deletions routeros/resource_ip_hotspot_walled_garden.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package routeros

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

/*
{
".id": "*6",
"action": "deny",
"disabled": "false",
"dst-host": "1.2.3.4",
"dst-port": "!123",
"dynamic": "false",
"hits": "0",
"method": "GET",
"path": "/sss",
"server": "server1",
"src-address": "4.3.2.1"
}
*/

// https://wiki.mikrotik.com/wiki/Manual:IP/Hotspot/Walled_Garden
func ResourceIpHotspotWalledGarden() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/hotspot/walled-garden"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields("hits", "dst_address"),

"action": {
Type: schema.TypeString,
Optional: true,
Description: "Action to perform, when packet matches the rule `allow` - allow access to the web-page without " +
"authorization, `deny` - the authorization is required to access the web-page.",
ValidateFunc: validation.StringInSlice([]string{"allow", "deny"}, false),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"dst_host": {
Type: schema.TypeString,
Optional: true,
Description: "Domain name of the destination web-server.",
},
"dst_port": {
Type: schema.TypeString,
Optional: true,
Description: "TCP port number, client sends request to.",
},
KeyDynamic: PropDynamicRo,
"method": {
Type: schema.TypeString,
Optional: true,
Description: "HTTP method of the request.",
},
"path": {
Type: schema.TypeString,
Optional: true,
Description: "The path of the request, path comes after `http://dst_host/`.",
},
"server": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the HotSpot server, rule is applied to.",
},
"src_address": {
Type: schema.TypeString,
Optional: true,
Description: "Source address of the user, usually IP address of the HotSpot client.",
},
}

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

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

import (
"fmt"
"testing"

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

const testIpHotspotWalledGarden = "routeros_ip_hotspot_walled_garden.test"

func TestAccIpHotspotWalledGardenTest_basic(t *testing.T) {
t.Parallel()
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/hotspot/walled-garden", "routeros_ip_hotspot_walled_garden"),
Steps: []resource.TestStep{
{
Config: testAccIpHotspotWalledGardenConfig(),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testIpHotspotWalledGarden),
resource.TestCheckResourceAttr(testIpHotspotWalledGarden, "action", "deny"),
resource.TestCheckResourceAttr(testIpHotspotWalledGarden, "dst_host", "1.2.3.4"),
resource.TestCheckResourceAttr(testIpHotspotWalledGarden, "dst_port", "!443"),
),
},
},
})

})
}
}

func testAccIpHotspotWalledGardenConfig() string {
return fmt.Sprintf(`%v
resource "routeros_ip_hotspot_walled_garden" "test" {
action = "deny"
dst_host = "1.2.3.4"
dst_port = "!443"
}
`, providerConfig)
}