From 7592f2f2fba7ea7d3a7875906b71a75126fd0f90 Mon Sep 17 00:00:00 2001 From: Vaerh Date: Mon, 6 Nov 2023 21:23:20 +0300 Subject: [PATCH] fix(vlan): Add Name-Id migration --- .../routeros_interface_vlan/import.sh | 5 ++- routeros/resource_interface_vlan.go | 13 ++++++- routeros/resource_interface_vlan_v0.go | 38 +++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 routeros/resource_interface_vlan_v0.go diff --git a/examples/resources/routeros_interface_vlan/import.sh b/examples/resources/routeros_interface_vlan/import.sh index 658ee1e2..da0ecd1b 100644 --- a/examples/resources/routeros_interface_vlan/import.sh +++ b/examples/resources/routeros_interface_vlan/import.sh @@ -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 \ No newline at end of file +#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" \ No newline at end of file diff --git a/routeros/resource_interface_vlan.go b/routeros/resource_interface_vlan.go index 47e8f4fb..19be9be8 100644 --- a/routeros/resource_interface_vlan.go +++ b/routeros/resource_interface_vlan.go @@ -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, @@ -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, } } diff --git a/routeros/resource_interface_vlan_v0.go b/routeros/resource_interface_vlan_v0.go new file mode 100644 index 00000000..d3a10f27 --- /dev/null +++ b/routeros/resource_interface_vlan_v0.go @@ -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, + }, + }, + } +}