-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #464
- Loading branch information
Showing
8 changed files
with
292 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
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 [/ get [print show-ids]] | ||
terraform import routeros_interface_lte.test *3 |
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 @@ | ||
|
||
resource "routeros_interface_lte" "test" { | ||
} |
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 [/ get [print show-ids]] | ||
terraform import routeros_interface_lte_apn.test *3 |
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,6 @@ | ||
|
||
resource "routeros_interface_lte_apn" "test" { | ||
name = "apn1" | ||
apn = "internet" | ||
authentication = "pap" | ||
} |
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,94 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
[] | ||
*/ | ||
|
||
// https://help.mikrotik.com/docs/display/ROS/LTE | ||
func ResourceInterfaceLte() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/interface/lte"), | ||
MetaId: PropId(Id), | ||
|
||
"allow_roaming": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "Enable data roaming for connecting to other countries data-providers. Not all LTE modems " + | ||
"support this feature. Some modems, that do not fully support this feature, will connect to the " + | ||
"network but will not establish an IP data connection with allow-roaming set to no.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"apn_profiles": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Which APN profile to use for this interface.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"band": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Description: "LTE Frequency band used in communication " + | ||
"[LTE Bands and bandwidths](https://en.wikipedia.org/wiki/LTE_frequency_bands#Frequency_bands_and_channel_bandwidths).", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeInt, | ||
}, | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"nr_band": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Description: "5G NR Frequency band used in communication [5G NR Bands and bandwidths](https://en.wikipedia.org/wiki/5G_NR_frequency_bands).", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeInt, | ||
}, | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
KeyComment: PropCommentRw, | ||
KeyDisabled: PropDisabledRw, | ||
"modem_init": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Modem init string (AT command that will be executed at modem startup).", | ||
}, | ||
KeyMtu: PropMtuRw(), | ||
KeyName: PropName("Descriptive name of the interface."), | ||
"network_mode": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Select/force mode for LTE interface to operate with.", | ||
ValidateFunc: validation.StringInSlice([]string{"3g", "gsm", "lte", "5g"}, false), | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"operator": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Description: "Used to lock the device to a specific operator full PLMN number is used for the lock " + | ||
"consisting of MCC+MNC. [PLMN codes](https://en.wikipedia.org/wiki/Public_land_mobile_network).", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"pin": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "SIM Card's PIN code.", | ||
}, | ||
} | ||
|
||
return &schema.Resource{ | ||
// FIXME | ||
CreateContext: DefaultSystemCreate(resSchema), | ||
ReadContext: DefaultSystemRead(resSchema), | ||
UpdateContext: DefaultSystemUpdate(resSchema), | ||
DeleteContext: DefaultSystemDelete(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,133 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
{ | ||
".id": "*1", | ||
"add-default-route": "true", | ||
"apn": "internet", | ||
"authentication": "none", | ||
"comment": "default", | ||
"default": "true", | ||
"default-route-distance": "2", | ||
"ip-type": "auto", | ||
"name": "default", | ||
"use-network-apn": "true", | ||
"use-peer-dns": "true" | ||
} | ||
*/ | ||
|
||
// https://help.mikrotik.com/docs/display/ROS/LTE#LTE-APNprofiles | ||
func ResourceInterfaceLteApn() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/interface/lte/apn"), | ||
MetaId: PropId(Id), | ||
|
||
"add_default_route": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "Whether to add a default route to forward all traffic over the LTE interface.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"apn": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Service Provider's Access Point Name.", | ||
}, | ||
"authentication": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Allowed protocol to use for authentication.", | ||
ValidateFunc: validation.StringInSlice([]string{"pap", "chap", "none"}, false), | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
KeyComment: PropCommentRw, | ||
"default_route_distance": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Description: "Sets distance value applied to auto-created default route, if add-default-route is also " + | ||
"selected. LTE route by default is with distance 2 to prefer wired routes over LTE.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"ip_type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Requested PDN type.", | ||
ValidateFunc: validation.StringInSlice([]string{"ipv4", "ipv4-ipv6", "ipv6"}, false), | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"ipv6_interface": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Interface on which to advertise IPv6 prefix.", | ||
}, | ||
KeyName: PropName("APN profile name"), | ||
"number": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Description: "APN profile number.", | ||
}, | ||
"passthrough_interface": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Interface to passthrough IP configuration (activates passthrough).", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"passthrough_mac": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "If set to auto, then will learn MAC from the first packet.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"passthrough_subnet_selection": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "`auto` selects the smallest possible subnet to be used for the passthrough interface. `p2p` " + | ||
"sets the passthrough interface subnet as `/32` and picks gateway address from `10.177.0.0/16` range. " + | ||
"The gateway address stays the same until the apn configuration is changed.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"password": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Password used if any of the authentication protocols are active.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"use_network_apn": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "Parameter is available starting from RouterOS v7 and used only for MBIM modems. If set to yes, " + | ||
"uses network provided APN.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"use_peer_dns": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "If set to yes, uses DNS received from LTE interface.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"user": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Username used if any of the authentication protocols are active.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
} | ||
|
||
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,48 @@ | ||
package routeros | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
const testInterfaceLteApn = "routeros_interface_lte_apn.test" | ||
|
||
func TestAccInterfaceLteApnTest_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, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInterfaceLteApnConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testResourcePrimaryInstanceId(testInterfaceLteApn), | ||
resource.TestCheckResourceAttr(testInterfaceLteApn, "name", "apn1"), | ||
resource.TestCheckResourceAttr(testInterfaceLteApn, "apn", "internet"), | ||
resource.TestCheckResourceAttr(testInterfaceLteApn, "authentication", "pap"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
}) | ||
} | ||
} | ||
|
||
func testAccInterfaceLteApnConfig() string { | ||
return fmt.Sprintf(`%v | ||
resource "routeros_interface_lte_apn" "test" { | ||
name = "apn1" | ||
apn = "internet" | ||
authentication = "pap" | ||
} | ||
`, providerConfig) | ||
} |