chore: work save

This commit is contained in:
Marcel S. Henselin 2026-01-27 16:43:53 +01:00
parent a60b1db1f4
commit 3e3f13d36d
7 changed files with 214 additions and 46 deletions

View file

@ -23,6 +23,8 @@ import (
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
)
const packageName = "postgresflexalpha"
// Ensure the implementation satisfies the expected interfaces.
var (
_ resource.Resource = &instanceResource{}
@ -212,13 +214,6 @@ func (r *instanceResource) Create(
return
}
model.InstanceId = types.StringValue(instanceId)
model.Id = utils.BuildInternalTerraformId(projectId, region, instanceId)
resp.Diagnostics.Append(resp.State.Set(ctx, &model)...)
if resp.Diagnostics.HasError() {
return
}
// Set data returned by API in identity
identity := InstanceResourceIdentityModel{
ProjectID: types.StringValue(projectId),
@ -301,6 +296,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
ctx = core.InitProviderContext(ctx)
// projectId := model.ProjectId.ValueString()
// region := r.providerData.GetRegionWithOverride(model.Region)
// instanceId := model.InstanceId.ValueString()
@ -334,14 +330,9 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
core.LogAndAddError(ctx, &resp.Diagnostics, functionErrorSummary, "instance_id not found in config")
return
}
region = identityData.Region.ValueString()
instanceId = identityData.InstanceID.ValueString()
}
tflog.Info(ctx, "Reading instance model", map[string]interface{}{
"projectId": projectId,
"region": region,
"instanceId": instanceId,
})
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = tflog.SetField(ctx, "region", region)
@ -453,7 +444,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
}
replInt32 := int32(model.Replicas.ValueInt64()) // nolint:gosec // check is performed above
payload := postgresflex.UpdateInstancePartiallyRequestPayload{
payload := postgresflex.UpdateInstanceRequestPayload{
BackupSchedule: model.BackupSchedule.ValueStringPointer(),
FlavorId: model.FlavorId.ValueStringPointer(),
Name: model.Name.ValueStringPointer(),
@ -463,7 +454,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
),
Acl: &netAcl,
},
Replicas: postgresflex.UpdateInstancePartiallyRequestPayloadGetReplicasAttributeType(&replInt32),
Replicas: postgresflex.UpdateInstanceRequestPayloadGetReplicasAttributeType(&replInt32),
RetentionDays: model.RetentionDays.ValueInt64Pointer(),
Storage: &postgresflex.StorageUpdate{
Size: model.Storage.Size.ValueInt64Pointer(),
@ -472,12 +463,12 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
}
// Update existing instance
err := r.client.UpdateInstancePartiallyRequest(
err := r.client.UpdateInstanceRequest(
ctx,
projectId,
region,
instanceId,
).UpdateInstancePartiallyRequestPayload(payload).Execute()
).UpdateInstanceRequestPayload(payload).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", err.Error())
return
@ -549,8 +540,6 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
// ImportState imports a resource into the Terraform state on success.
// The expected format of the resource import identifier is: project_id,region,instance_id
func (r *instanceResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
tflog.Debug(ctx, "ImportState called with id:", map[string]interface{}{"id": req.ID})
ctx = core.InitProviderContext(ctx)
if req.ID != "" {