Skip to content

Commit

Permalink
fix(vlan): Add Name-Id migration
Browse files Browse the repository at this point in the history
  • Loading branch information
vaerh committed Nov 6, 2023
1 parent 6b326c0 commit 7592f2f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
5 changes: 3 additions & 2 deletions examples/resources/routeros_interface_vlan/import.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Import with the name of the vlan interface in case of the example use VLAN_TEST
terraform import routeros_interface_vlan.interface_vlan VLAN_TEST
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/interface/vlan get [print show-ids]]
terraform import routeros_interface_vlan.interface_vlan "*1"
13 changes: 11 additions & 2 deletions routeros/resource_interface_vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
// ResourceInterfaceVlan https://wiki.mikrotik.com/wiki/Manual:Interface/VLAN
func ResourceInterfaceVlan() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/vlan"),
MetaId: PropId(Name),
MetaResourcePath: PropResourcePath("/interface/vlan"),
MetaId: PropId(Id),

KeyArp: PropArpRw,
KeyArpTimeout: PropArpTimeoutRw,
Expand Down Expand Up @@ -45,6 +45,15 @@ func ResourceInterfaceVlan() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: ResourceInterfaceVlanV0().CoreConfigSchema().ImpliedType(),
Upgrade: stateMigrationNameToId(resSchema[MetaResourcePath].Default.(string)),
Version: 0,
},
},

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

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

func ResourceInterfaceVlanV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/vlan"),
MetaId: PropId(Name),

KeyArp: PropArpRw,
KeyArpTimeout: PropArpTimeoutRw,
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
KeyInterface: PropInterfaceRw,
KeyL2Mtu: PropL2MtuRo,
KeyLoopProtect: PropLoopProtectRw,
KeyLoopProtectDisableTime: PropLoopProtectDisableTimeRw,
KeyLoopProtectSendInterval: PropLoopProtectSendIntervalRw,
KeyLoopProtectStatus: PropLoopProtectStatusRo,
KeyMacAddress: PropMacAddressRo,
KeyMtu: PropMtuRw(),
KeyName: PropNameForceNewRw,
KeyRunning: PropRunningRo,
"use_service_tag": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"vlan_id": {
Type: schema.TypeInt,
Required: true,
},
},
}
}

0 comments on commit 7592f2f

Please sign in to comment.