-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add resource routeros_ipv6_neighbor_discovery #362
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
examples/resources/routeros_ipv6_neighbor_discovery/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 [/ipv6/nd get [print show-ids]] | ||
terraform import routeros_ipv6_neighbor_discovery.ndether1 "*0" |
19 changes: 19 additions & 0 deletions
19
examples/resources/routeros_ipv6_neighbor_discovery/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,19 @@ | ||
|
||
resource "routeros_ipv6_neighbor_discovery" "test" { | ||
interface = "ether1" | ||
hop_limit = 33 | ||
advertise_dns = false | ||
advertise_mac_address = true | ||
disabled = false | ||
managed_address_configuration = true | ||
mtu = 9000 | ||
other_configuration = true | ||
pref64_prefixes = [] | ||
ra_delay = "3s" | ||
ra_interval = "3m20s-10m" | ||
ra_lifetime = "30m" | ||
ra_preference = "high" | ||
reachable_time = "10m" | ||
retransmit_interval = "12m" | ||
} | ||
` |
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
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
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,153 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
[ | ||
{ | ||
".id": "*3", | ||
"advertise-dns": "false", | ||
"advertise-mac-address": "true", | ||
"default": "false", | ||
"disabled": "false", | ||
"dns": "", | ||
"hop-limit": "unspecified", | ||
"interface": "vlan-wifi-XXX", | ||
"invalid": "false", | ||
"managed-address-configuration": "true", | ||
"mtu": "unspecified", | ||
"other-configuration": "true", | ||
"pref64": "", | ||
"ra-delay": "3s", | ||
"ra-interval": "3m20s-10m", | ||
"ra-lifetime": "30m", | ||
"ra-preference": "high", | ||
"reachable-time": "unspecified", | ||
"retransmit-interval": "unspecified" | ||
} | ||
] | ||
*/ | ||
|
||
// ResourceIPv6NeighborDiscovery https://help.mikrotik.com/docs/display/ROS/IPv6+Neighbor+Discovery | ||
func ResourceIPv6NeighborDiscovery() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/ipv6/nd"), | ||
MetaId: PropId(Id), | ||
MetaDropByValue: PropDropByValue("unspecified"), | ||
"advertise_dns": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "Option to redistribute DNS server information using RADVD. You will need a running client-side software with Router Advertisement DNS support to take advantage of the advertised DNS information.", | ||
Default: true, | ||
}, | ||
"advertise_mac_address": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "When set, the link-layer address of the outgoing interface is included in the RA.", | ||
Default: true, | ||
}, | ||
KeyComment: PropCommentRw, | ||
"dns_servers": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Specify a single IPv6 address or list of addresses that will be provided to hosts for DNS server configuration.", | ||
ValidateFunc: validation.IsCIDR, | ||
}, | ||
KeyDisabled: PropDisabledRw, | ||
"hop_limit": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Description: "The default value that should be placed in the Hop Count field of the IP header for outgoing (unicast) IP packets.", | ||
ValidateFunc: validation.IntBetween(0, 255), | ||
}, | ||
"interface": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The interface on which to run neighbor discovery." + | ||
"all - run ND on all running interfaces.", | ||
}, | ||
"managed_address_configuration": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "Name of the IPv6 pool in which received IPv6 prefix will be added", | ||
}, | ||
"mtu": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Description: "The flag indicates whether hosts should use stateful autoconfiguration (DHCPv6) to obtain addresses", | ||
ValidateFunc: validation.IntBetween(0, 4294967295), | ||
}, | ||
"other_configuration": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "The flag indicates whether hosts should use stateful autoconfiguration to obtain additional information (excluding addresses).", | ||
}, | ||
"pref64_prefixes": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Description: "Specify IPv6 prefix or list of prefixes within /32, /40. /48, /56, /64, or /96 subnet that will be provided to hosts as NAT64 prefixes.", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateFunc: validation.IsCIDR, | ||
}, | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"ra_delay": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The minimum time allowed between sending multicast router advertisements from the interface.", | ||
Default: "3s", | ||
}, | ||
"ra_interval": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The min-max interval allowed between sending unsolicited multicast router advertisements from the interface.", | ||
Default: "3m20s-10m", | ||
}, | ||
"ra_preference": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Specify the router preference that is communicated to IPv6 hosts through router advertisements." + | ||
"The preference value in the router advertisements enables IPv6 hosts to select a default router to reach a remote destination", | ||
Default: "medium", | ||
ValidateFunc: validation.StringInSlice([]string{"low", "medium", "high"}, false), | ||
}, | ||
"ra_lifetime": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Specify the router preference that is communicated to IPv6 hosts through router advertisements." + | ||
"The preference value in the router advertisements enables IPv6 hosts to select a default router to reach a remote destination", | ||
Default: "30m", | ||
}, | ||
"reachable_time": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Specify the router preference that is communicated to IPv6 hosts through router advertisements." + | ||
"The preference value in the router advertisements enables IPv6 hosts to select a default router to reach a remote destination", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"retransmit_interval": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The time between retransmitted Neighbor Solicitation messages." + | ||
"Used by address resolution and the Neighbor Unreachability Detection algorithm (see Sections 7.2 and 7.3 of RFC 2461)", | ||
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool { | ||
return true | ||
}, | ||
}, | ||
} | ||
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,102 @@ | ||
package routeros | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
const testIPv6NeighborDiscoveryAddress = "routeros_ipv6_neighbor_discovery.test" | ||
|
||
func TestAccIPv6FNeighborDiscoveryTest_full(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("/ipv6/nd", "routeros_ipv6_neighbor_discovery"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFullIPv6NeighborDiscoveryConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testResourcePrimaryInstanceId(testIPv6NeighborDiscoveryAddress), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "interface", "ether1"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "hop_limit", "33"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "advertise_dns", "false"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "advertise_mac_address", "true"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "disabled", "false"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "managed_address_configuration", "true"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "mtu", "9000"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "other_configuration", "true"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "ra_delay", "3s"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "ra_interval", "3m20s-10m"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "ra_lifetime", "30m"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "ra_preference", "high"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "reachable_time", "10m"), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "retransmit_interval", "12m"), | ||
), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func TestAccIPv6FNeighborDiscoveryTest_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("/ipv6/nd", "routeros_ipv6_neighbor_discovery"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSimpleIPv6NeighborDiscoveryConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testResourcePrimaryInstanceId(testIPv6NeighborDiscoveryAddress), | ||
resource.TestCheckResourceAttr(testIPv6NeighborDiscoveryAddress, "interface", "ether1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func testAccFullIPv6NeighborDiscoveryConfig() string { | ||
return providerConfig + ` | ||
|
||
resource "routeros_ipv6_neighbor_discovery" "test" { | ||
interface = "ether1" | ||
hop_limit = 33 | ||
advertise_dns = false | ||
advertise_mac_address = true | ||
disabled = false | ||
managed_address_configuration = true | ||
mtu = 9000 | ||
other_configuration = true | ||
pref64_prefixes = [] | ||
ra_delay = "3s" | ||
ra_interval = "3m20s-10m" | ||
ra_lifetime = "30m" | ||
ra_preference = "high" | ||
reachable_time = "10m" | ||
retransmit_interval = "12m" | ||
} | ||
` | ||
} | ||
|
||
func testAccSimpleIPv6NeighborDiscoveryConfig() string { | ||
return providerConfig + ` | ||
|
||
resource "routeros_ipv6_neighbor_discovery" "test" { | ||
interface = "ether1" | ||
} | ||
` | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the problem. It is contained in
DiffSuppressFunc
.JSON generation in the current implementation:
JSON with our nice and working
AlwaysPresentNotUserProvided
functionWe should remove all such functions if they give such problems. If I remember correctly, we used them somewhere....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much... I left this here by accident while I was testing something. My apologies, I'll fix it soon.