From e2f737084955f3c709f8fb458f07c685de330dc2 Mon Sep 17 00:00:00 2001 From: Andre Harms Date: Thu, 5 Feb 2026 21:13:48 +0100 Subject: [PATCH] feat: implement IdentitySchema for user resource to define unique identification fields --- .../postgresflexalpha/user/resource.go | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/stackit/internal/services/postgresflexalpha/user/resource.go b/stackit/internal/services/postgresflexalpha/user/resource.go index 06c2a1a5..c0934786 100644 --- a/stackit/internal/services/postgresflexalpha/user/resource.go +++ b/stackit/internal/services/postgresflexalpha/user/resource.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/resource/identityschema" "github.com/hashicorp/terraform-plugin-framework/resource/schema" postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha" postgresflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/user/resources_gen" @@ -31,6 +32,7 @@ var ( _ resource.ResourceWithConfigure = &userResource{} _ resource.ResourceWithImportState = &userResource{} _ resource.ResourceWithModifyPlan = &userResource{} + _ resource.ResourceWithIdentity = &userResource{} ) // ResourceModel represents the Terraform resource state for a PostgreSQL Flex user. @@ -387,6 +389,30 @@ func (r *userResource) Delete( tflog.Info(ctx, "Postgres Flex user deleted") } +// IdentitySchema defines the fields that are required to uniquely identify a resource. +func (r *userResource) IdentitySchema( + _ context.Context, + _ resource.IdentitySchemaRequest, + response *resource.IdentitySchemaResponse, +) { + response.IdentitySchema = identityschema.Schema{ + Attributes: map[string]identityschema.Attribute{ + "project_id": identityschema.StringAttribute{ + RequiredForImport: true, + }, + "region": identityschema.StringAttribute{ + RequiredForImport: true, + }, + "instance_id": identityschema.StringAttribute{ + RequiredForImport: true, + }, + "user_id": identityschema.Int64Attribute{ + RequiredForImport: true, + }, + }, + } +} + // ImportState imports a resource into the Terraform state on success. // The expected format of the resource import identifier is: project_id,zone_id,record_set_id func (r *userResource) ImportState(