-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hotspot): Add new resource
routeros_ip_hotspot_walled_garden_ip
- Loading branch information
Showing
5 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
examples/resources/routeros_ip_hotspot_walled_garden_ip/import.sh
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,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/ip/hotspot/walled-garden/ip get [print show-ids]] | ||
terraform import routeros_ip_hotspot_walled_garden_ip.test *3 |
9 changes: 9 additions & 0 deletions
9
examples/resources/routeros_ip_hotspot_walled_garden_ip/resource.tf
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,9 @@ | ||
resource "routeros_ip_hotspot_walled_garden_ip" "test" { | ||
action = "reject" | ||
dst_address = "!0.0.0.0" | ||
dst_address_list = "dlist" | ||
dst_port = "0-65535" | ||
protocol = "tcp" | ||
src_address = "0.0.0.0" | ||
src_address_list = "slist" | ||
} |
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,100 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
{ | ||
".id": "*4", | ||
"action": "reject", | ||
"disabled": "false", | ||
"dst-address": "!0.0.0.0", | ||
"dst-address-list": "bbb", | ||
"dst-port": "0-65535", | ||
"invalid": "false", | ||
"protocol": "tcp", | ||
"server": "server1", | ||
"src-address": "0.0.0.0", | ||
"src-address-list": "aaa" | ||
} | ||
*/ | ||
|
||
// https://wiki.mikrotik.com/wiki/Manual:IP/Hotspot/Walled_Garden#IP_Walled_Garden | ||
func ResourceIpHotspotWalledGardenIp() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/ip/hotspot/walled-garden/ip"), | ||
MetaId: PropId(Id), | ||
|
||
"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 reject - the authorization " + | ||
"is required to access the resource, ICMP reject message will be sent to client, when packet will match " + | ||
"the rule.", | ||
ValidateFunc: validation.StringInSlice([]string{"allow", "deny", "reject"}, false), | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
KeyComment: PropCommentRw, | ||
KeyDisabled: PropDisabledRw, | ||
"dst_address": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Destination IP address, IP address of the WEB-server. Ignored if dst-host is already specified.", | ||
ConflictsWith: []string{"dst_host"}, | ||
}, | ||
"dst_address_list": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Destination IP address list. Ignored if dst-host is already specified.", | ||
}, | ||
"dst_host": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Domain name of the destination web-server. When this parameter is specified dynamic entry " + | ||
"is added to Walled Garden.", | ||
ConflictsWith: []string{"dst_address"}, | ||
}, | ||
"dst_port": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "TCP port number, client sends request to.", | ||
}, | ||
KeyInvalid: PropInvalidRo, | ||
"protocol": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "IP protocol.", | ||
}, | ||
"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.", | ||
}, | ||
"src_address_list": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Source IP address list.", | ||
}, | ||
} | ||
|
||
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,57 @@ | ||
package routeros | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
const testIpHotspotWalledGardenIp = "routeros_ip_hotspot_walled_garden_ip.test" | ||
|
||
func TestAccIpHotspotWalledGardenIpTest_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/ip", "routeros_ip_hotspot_walled_garden_ip"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccIpHotspotWalledGardenIpConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testResourcePrimaryInstanceId(testIpHotspotWalledGardenIp), | ||
resource.TestCheckResourceAttr(testIpHotspotWalledGardenIp, "action", "reject"), | ||
resource.TestCheckResourceAttr(testIpHotspotWalledGardenIp, "dst_address", "!0.0.0.0"), | ||
resource.TestCheckResourceAttr(testIpHotspotWalledGardenIp, "dst_address_list", "dlist"), | ||
resource.TestCheckResourceAttr(testIpHotspotWalledGardenIp, "dst_port", "0-65535"), | ||
resource.TestCheckResourceAttr(testIpHotspotWalledGardenIp, "protocol", "tcp"), | ||
resource.TestCheckResourceAttr(testIpHotspotWalledGardenIp, "src_address", "0.0.0.0"), | ||
resource.TestCheckResourceAttr(testIpHotspotWalledGardenIp, "src_address_list", "slist"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
}) | ||
} | ||
} | ||
|
||
func testAccIpHotspotWalledGardenIpConfig() string { | ||
return fmt.Sprintf(`%v | ||
resource "routeros_ip_hotspot_walled_garden_ip" "test" { | ||
action = "reject" | ||
dst_address = "!0.0.0.0" | ||
dst_address_list = "dlist" | ||
dst_port = "0-65535" | ||
protocol = "tcp" | ||
src_address = "0.0.0.0" | ||
src_address_list = "slist" | ||
} | ||
`, providerConfig) | ||
} |