Skip to content

Commit

Permalink
fix(wg): 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 30c8f37 commit d676b8b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
5 changes: 3 additions & 2 deletions examples/resources/routeros_interface_wireguard/import.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Import with the name of the wireguard interface in case of the example use test_wg_interface
terraform import routeros_interface_wireguard.test_wg_interface test_wg_interface
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/interface/wireguard get [print show-ids]]
terraform import routeros_interface_wireguard.test_wg_interface "*1"
11 changes: 10 additions & 1 deletion routeros/resource_interface_wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func ResourceInterfaceWireguard() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/wireguard"),
MetaId: PropId(Name),
MetaId: PropId(Id),

KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
Expand Down Expand Up @@ -59,6 +59,15 @@ func ResourceInterfaceWireguard() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

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

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

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

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

KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"listen_port": {
Type: schema.TypeInt,
Required: true,
Description: "Port for WireGuard service to listen on for incoming sessions.",
ValidateFunc: validation.IntBetween(1, 65535),
},
KeyMtu: PropMtuRw(),
KeyName: PropNameForceNewRw,
"private_key": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Sensitive: true,
Description: "A base64 private key. If not specified, it will be automatically " +
"generated upon interface creation.",
},
"public_key": {
Type: schema.TypeString,
Computed: true,
Description: "A base64 public key is calculated from the private key.",
},
KeyRunning: PropRunningRo,
},
}
}

0 comments on commit d676b8b

Please sign in to comment.