chore: work save
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m57s
CI Workflow / CI run tests (pull_request) Failing after 5m5s
CI Workflow / CI run build and linting (pull_request) Failing after 4m50s
CI Workflow / Code coverage report (pull_request) Has been skipped

This commit is contained in:
Marcel S. Henselin 2026-03-05 15:11:15 +01:00
parent 411e99739a
commit d6d3a795bb
118 changed files with 3101 additions and 18065 deletions

View file

@ -12,8 +12,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
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"
postgresflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
postgresflexalphaWait "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/wait/postgresflexalpha"
@ -55,12 +55,12 @@ type UserResourceIdentityModel struct {
ProjectID types.String `tfsdk:"project_id"`
Region types.String `tfsdk:"region"`
InstanceID types.String `tfsdk:"instance_id"`
UserID types.Int64 `tfsdk:"user_id"`
UserID types.Int32 `tfsdk:"user_id"`
}
// userResource implements the resource handling for a PostgreSQL Flex user.
type userResource struct {
client *postgresflex.APIClient
client *v3alpha1api.APIClient
providerData core.ProviderData
}
@ -202,14 +202,14 @@ func (r *userResource) Create(
}
// Generate API request body from model
payload, err := toCreatePayload(&model, &roles)
payload, err := toCreatePayload(&model, roles)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Creating API payload: %v", err))
return
}
// Create new user
userResp, err := r.client.CreateUserRequest(
userResp, err := r.client.DefaultAPI.CreateUserRequest(
ctx,
arg.projectId,
arg.region,
@ -221,7 +221,7 @@ func (r *userResource) Create(
}
id, ok := userResp.GetIdOk()
if !ok || id == 0 {
if !ok || *id == 0 {
core.LogAndAddError(
ctx,
&resp.Diagnostics,
@ -230,7 +230,7 @@ func (r *userResource) Create(
)
return
}
arg.userId = id
arg.userId = *id
ctx = tflog.SetField(ctx, "user_id", id)
@ -241,25 +241,25 @@ func (r *userResource) Create(
ProjectID: types.StringValue(arg.projectId),
Region: types.StringValue(arg.region),
InstanceID: types.StringValue(arg.instanceId),
UserID: types.Int64Value(id),
UserID: types.Int32Value(*id),
}
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
if resp.Diagnostics.HasError() {
return
}
model.Id = types.Int64Value(id)
model.UserId = types.Int64Value(id)
model.Id = types.Int32Value(*id)
model.UserId = types.Int32Value(*id)
model.Password = types.StringValue(userResp.GetPassword())
model.Status = types.StringValue(userResp.GetStatus())
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
ctx,
r.client,
r.client.DefaultAPI,
arg.projectId,
arg.instanceId,
arg.region,
id,
*id,
).SetSleepBeforeWait(
10 * time.Second,
).SetTimeout(
@ -276,7 +276,7 @@ func (r *userResource) Create(
return
}
if waitResp.Id == nil {
if waitResp.Id == 0 {
core.LogAndAddError(
ctx,
&resp.Diagnostics,
@ -285,7 +285,7 @@ func (r *userResource) Create(
)
return
}
if waitResp.Id == nil || *waitResp.Id != id {
if waitResp.Id != *id {
core.LogAndAddError(
ctx,
&resp.Diagnostics,
@ -336,11 +336,11 @@ func (r *userResource) Read(
// Read resource state
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
ctx,
r.client,
r.client.DefaultAPI,
arg.projectId,
arg.instanceId,
arg.region,
model.UserId.ValueInt64(),
model.UserId.ValueInt32(),
).SetSleepBeforeWait(
10 * time.Second,
).SetTimeout(
@ -357,7 +357,7 @@ func (r *userResource) Read(
return
}
if waitResp.Id == nil || *waitResp.Id != model.UserId.ValueInt64() {
if waitResp.Id != model.UserId.ValueInt32() {
core.LogAndAddError(
ctx,
&resp.Diagnostics,
@ -366,7 +366,7 @@ func (r *userResource) Read(
)
return
}
arg.userId = *waitResp.Id
arg.userId = waitResp.Id
ctx = core.LogResponse(ctx)
@ -375,7 +375,7 @@ func (r *userResource) Read(
ProjectID: types.StringValue(arg.projectId),
Region: types.StringValue(arg.region),
InstanceID: types.StringValue(arg.instanceId),
UserID: types.Int64Value(arg.userId),
UserID: types.Int32Value(arg.userId),
}
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
if resp.Diagnostics.HasError() {
@ -429,7 +429,7 @@ func (r *userResource) Update(
}
// Generate API request body from model
payload, err := toUpdatePayload(&model, &roles)
payload, err := toUpdatePayload(&model, roles)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", fmt.Sprintf("Updating API payload: %v", err))
return
@ -443,7 +443,7 @@ func (r *userResource) Update(
userId := int32(userId64) // nolint:gosec // check is performed above
// Update existing instance
err = r.client.UpdateUserRequest(
err = r.client.DefaultAPI.UpdateUserRequest(
ctx,
arg.projectId,
arg.region,
@ -462,7 +462,7 @@ func (r *userResource) Update(
ProjectID: types.StringValue(arg.projectId),
Region: types.StringValue(arg.region),
InstanceID: types.StringValue(arg.instanceId),
UserID: types.Int64Value(userId64),
UserID: types.Int32Value(userId64),
}
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
if resp.Diagnostics.HasError() {
@ -472,11 +472,11 @@ func (r *userResource) Update(
// Verify update
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
ctx,
r.client,
r.client.DefaultAPI,
arg.projectId,
arg.instanceId,
arg.region,
model.UserId.ValueInt64(),
model.UserId.ValueInt32(),
).SetSleepBeforeWait(
10 * time.Second,
).SetTimeout(
@ -493,7 +493,7 @@ func (r *userResource) Update(
return
}
if waitResp.Id == nil || *waitResp.Id != model.UserId.ValueInt64() {
if waitResp.Id != model.UserId.ValueInt32() {
core.LogAndAddError(
ctx,
&resp.Diagnostics,
@ -502,7 +502,7 @@ func (r *userResource) Update(
)
return
}
arg.userId = *waitResp.Id
arg.userId = waitResp.Id
// Set state to fully populated data
diags = resp.State.Set(ctx, stateModel)
@ -555,7 +555,7 @@ func (r *userResource) Delete(
userId := int32(userId64) // nolint:gosec // check is performed above
// Delete existing record set
err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
err := r.client.DefaultAPI.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err))
}
@ -571,7 +571,7 @@ func (r *userResource) Delete(
// if exists {
// core.LogAndAddError(
// ctx, &resp.Diagnostics, "Error deleting user",
// fmt.Sprintf("User ID '%v' resource still exists after deletion", model.UserId.ValueInt64()),
// fmt.Sprintf("User ID '%v' resource still exists after deletion", model.UserId.ValueInt32()),
// )
// return
//}
@ -598,7 +598,7 @@ func (r *userResource) IdentitySchema(
"instance_id": identityschema.StringAttribute{
RequiredForImport: true,
},
"user_id": identityschema.Int64Attribute{
"user_id": identityschema.Int32Attribute{
RequiredForImport: true,
},
},
@ -610,7 +610,7 @@ type clientArg struct {
projectId string
instanceId string
region string
userId int64
userId int32
}
// ImportState imports a resource into the Terraform state on success.
@ -668,7 +668,7 @@ func (r *userResource) ImportState(
projectId := identityData.ProjectID.ValueString()
region := identityData.Region.ValueString()
instanceId := identityData.InstanceID.ValueString()
userId := identityData.UserID.ValueInt64()
userId := identityData.UserID.ValueInt32()
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), projectId)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), region)...)
@ -684,15 +684,15 @@ func (r *userResource) extractIdentityData(
identity UserResourceIdentityModel,
) (*clientArg, error) {
var projectId, region, instanceId string
var userId int64
var userId int32
if !model.UserId.IsNull() && !model.UserId.IsUnknown() {
userId = model.UserId.ValueInt64()
userId = model.UserId.ValueInt32()
} else {
if identity.UserID.IsNull() || identity.UserID.IsUnknown() {
return nil, fmt.Errorf("user_id not found in config")
}
userId = identity.UserID.ValueInt64()
userId = identity.UserID.ValueInt32()
}
if !model.ProjectId.IsNull() && !model.ProjectId.IsUnknown() {