Skip to content

Commit

Permalink
use uppercase for import ID field (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
maksym-nazarenko authored Sep 17, 2023
1 parent dcfb562 commit dab9a0c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions mikrotik/internal/utils/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"strings"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand All @@ -28,3 +30,12 @@ func ImportStateContextUppercaseWrapper(wrappedFunc schema.StateContextFunc) sch
return wrappedFunc(ctx, rd, i)
}
}

// ImportUppercaseWrapper is ImportStateContextUppercaseWrapper equivalent for PluginFramework.
func ImportUppercaseWrapper(wrappedFunc importStateFunc) importStateFunc {
return func(ctx context.Context, p path.Path, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
wrappedFunc(ctx, p, resource.ImportStateRequest{ID: strings.ToUpper(req.ID)}, resp)
}
}

type importStateFunc = func(context.Context, path.Path, resource.ImportStateRequest, *resource.ImportStateResponse)
3 changes: 2 additions & 1 deletion mikrotik/resource_dhcp_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/ddelnano/terraform-provider-mikrotik/client"
"github.com/ddelnano/terraform-provider-mikrotik/mikrotik/internal/utils"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -123,7 +124,7 @@ func (r *dhcpLease) Delete(ctx context.Context, req resource.DeleteRequest, resp

func (r *dhcpLease) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
// Retrieve import ID and save to id attribute
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
utils.ImportUppercaseWrapper(resource.ImportStatePassthroughID)(ctx, path.Root("id"), req, resp)
}

type dhcpLeaseModel struct {
Expand Down
3 changes: 2 additions & 1 deletion mikrotik/resource_ipv6_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/ddelnano/terraform-provider-mikrotik/client"
"github.com/ddelnano/terraform-provider-mikrotik/mikrotik/internal/utils"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -136,7 +137,7 @@ func (r *ipv6Address) Delete(ctx context.Context, req resource.DeleteRequest, re

func (r *ipv6Address) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
// Retrieve import ID and save to id attribute
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
utils.ImportUppercaseWrapper(resource.ImportStatePassthroughID)(ctx, path.Root("id"), req, resp)
}

type ipv6AddressModel struct {
Expand Down

0 comments on commit dab9a0c

Please sign in to comment.