diff --git a/mikrotik/internal/utils/provider.go b/mikrotik/internal/utils/provider.go index 25b7dce3..bb9b99c0 100644 --- a/mikrotik/internal/utils/provider.go +++ b/mikrotik/internal/utils/provider.go @@ -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" ) @@ -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) diff --git a/mikrotik/resource_dhcp_lease.go b/mikrotik/resource_dhcp_lease.go index 35e506d9..bd3827b0 100644 --- a/mikrotik/resource_dhcp_lease.go +++ b/mikrotik/resource_dhcp_lease.go @@ -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" @@ -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 { diff --git a/mikrotik/resource_ipv6_address.go b/mikrotik/resource_ipv6_address.go index 765f3291..95b1b66c 100644 --- a/mikrotik/resource_ipv6_address.go +++ b/mikrotik/resource_ipv6_address.go @@ -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" @@ -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 {