Skip to content

Commit

Permalink
fix: Add compatibility layer for the VRF property in RADIUS incoming …
Browse files Browse the repository at this point in the history
…resource
  • Loading branch information
dokmic authored and vaerh committed Nov 15, 2023
1 parent 6fb0a23 commit 96a5354
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions routeros/resource_radius.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package routeros

import (
"context"

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

const vrfKey = "vrf"

// https://help.mikrotik.com/docs/display/ROS/RADIUS#RADIUS-RADIUSClient
func ResourceRadius() *schema.Resource {
resSchema := map[string]*schema.Schema{
Expand Down Expand Up @@ -126,17 +131,16 @@ func ResourceRadiusIncoming() *schema.Resource {
Description: "The port number to listen for the requests on.",
ValidateFunc: validation.IntBetween(0, 65535),
},
"vrf": {
vrfKey: {
Type: schema.TypeString,
Optional: true,
Default: "main",
Description: "VRF on which service is listening for incoming connections.",
Description: "VRF on which service is listening for incoming connections. This option is available in RouterOS starting from version 7.4.",
},
}

return &schema.Resource{
CreateContext: DefaultSystemCreate(resSchema),
ReadContext: DefaultSystemRead(resSchema),
ReadContext: compatibleSystemRead(resSchema),
UpdateContext: DefaultSystemUpdate(resSchema),
DeleteContext: DefaultSystemDelete(resSchema),

Expand All @@ -147,3 +151,14 @@ func ResourceRadiusIncoming() *schema.Resource {
Schema: resSchema,
}
}

func compatibleSystemRead(s map[string]*schema.Schema) schema.ReadContextFunc {
return func (ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diags := SystemResourceRead(ctx, s, d, m)
if _, exists := d.GetOk(vrfKey); exists {
s[vrfKey].Default = "main"
}

return diags
}
}

0 comments on commit 96a5354

Please sign in to comment.