From fdbd68f21f2ef5284b0e8529095a4cb5a3a76067 Mon Sep 17 00:00:00 2001 From: Vaerh Date: Mon, 6 Nov 2023 20:53:31 +0300 Subject: [PATCH] fix(eoip): Add Name-Id migration --- .../routeros_interface_eoip/import.sh | 5 ++- routeros/resource_interface_eoip.go | 9 ++++ routeros/resource_interface_eoip_v0.go | 43 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 routeros/resource_interface_eoip_v0.go diff --git a/examples/resources/routeros_interface_eoip/import.sh b/examples/resources/routeros_interface_eoip/import.sh index 733a2b71..bba87b94 100644 --- a/examples/resources/routeros_interface_eoip/import.sh +++ b/examples/resources/routeros_interface_eoip/import.sh @@ -1,2 +1,3 @@ -# Import with the name of the EoIP interface in case of the example, use `eoip-tunnel1` -terraform import routeros_interface_eoip.eoip_tunnel1 eoip-tunnel1 \ No newline at end of file +#The ID can be found via API or the terminal +#The command for the terminal is -> :put [/interface/eoip get [print show-ids]] +terraform import routeros_interface_eoip.eoip_tunnel1 *B \ No newline at end of file diff --git a/routeros/resource_interface_eoip.go b/routeros/resource_interface_eoip.go index 4686335c..2936a81f 100644 --- a/routeros/resource_interface_eoip.go +++ b/routeros/resource_interface_eoip.go @@ -57,6 +57,15 @@ func ResourceInterfaceEoip() *schema.Resource { }), DeleteContext: DefaultDelete(resSchema), + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: ResourceInterfaceEoipV0().CoreConfigSchema().ImpliedType(), + Upgrade: stateMigrationNameToId(resSchema[MetaResourcePath].Default.(string)), + Version: 0, + }, + }, + Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, diff --git a/routeros/resource_interface_eoip_v0.go b/routeros/resource_interface_eoip_v0.go new file mode 100644 index 00000000..07a2c171 --- /dev/null +++ b/routeros/resource_interface_eoip_v0.go @@ -0,0 +1,43 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func ResourceInterfaceEoipV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/interface/eoip"), + MetaId: PropId(Name), + + KeyActualMtu: PropActualMtuRo, + KeyArp: PropArpRw, + KeyArpTimeout: PropArpTimeoutRw, + KeyAllowFastPath: PropAllowFastPathRw, + KeyClampTcpMss: PropClampTcpMssRw, + KeyComment: PropCommentRw, + KeyDisabled: PropDisabledRw, + KeyDontFragment: PropDontFragmentRw, + KeyDscp: PropDscpRw, + KeyIpsecSecret: PropIpsecSecretRw, + KeyKeepalive: PropKeepaliveRw, + KeyL2Mtu: PropL2MtuRo, + KeyLocalAddress: PropLocalAddressRw, + KeyLoopProtect: PropLoopProtectRw, + KeyLoopProtectDisableTime: PropLoopProtectDisableTimeRw, + KeyLoopProtectSendInterval: PropLoopProtectSendIntervalRw, + KeyLoopProtectStatus: PropLoopProtectStatusRo, + KeyMacAddress: PropMacAddressRo, + KeyMtu: PropMtuRw(), + KeyName: PropNameForceNewRw, + KeyRemoteAddress: PropRemoteAddressRw, + KeyRunning: PropRunningRo, + "tunnel_id": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + Description: "Unique tunnel identifier, which must match the other side of the tunnel.", + }, + }, + } +}