From 8a27483b81f460405e5704bc56d56864affa620f Mon Sep 17 00:00:00 2001 From: Andre Harms Date: Tue, 10 Feb 2026 13:58:06 +0100 Subject: [PATCH 1/3] fix: tests --- .../postgresflexalpha/database/mapper_test.go | 7 ++++++- .../services/postgresflexalpha/user/mapper_test.go | 5 ++++- .../services/sqlserverflexalpha/user/resource.go | 2 ++ stackit/internal/wait/postgresflexalpha/wait.go | 14 ++++++++------ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/stackit/internal/services/postgresflexalpha/database/mapper_test.go b/stackit/internal/services/postgresflexalpha/database/mapper_test.go index a2f18c12..97212237 100644 --- a/stackit/internal/services/postgresflexalpha/database/mapper_test.go +++ b/stackit/internal/services/postgresflexalpha/database/mapper_test.go @@ -34,7 +34,12 @@ func TestMapFields(t *testing.T) { Name: utils.Ptr("my-db"), Owner: utils.Ptr("\"my-owner\""), }, - model: &dataSourceModel{}, + model: &dataSourceModel{ + DatabaseModel: datasource.DatabaseModel{ + ProjectId: types.StringValue("my-project"), + InstanceId: types.StringValue("my-instance"), + }, + }, region: "eu01", }, expected: expected{ diff --git a/stackit/internal/services/postgresflexalpha/user/mapper_test.go b/stackit/internal/services/postgresflexalpha/user/mapper_test.go index 6eeff9f0..37410b19 100644 --- a/stackit/internal/services/postgresflexalpha/user/mapper_test.go +++ b/stackit/internal/services/postgresflexalpha/user/mapper_test.go @@ -164,6 +164,7 @@ func TestMapFieldsCreate(t *testing.T) { }, testRegion, resourceModel{ + Id: types.Int64Value(1), UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), @@ -185,6 +186,7 @@ func TestMapFieldsCreate(t *testing.T) { }, testRegion, resourceModel{ + Id: types.Int64Value(1), UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), @@ -193,7 +195,7 @@ func TestMapFieldsCreate(t *testing.T) { Password: types.StringNull(), Region: types.StringValue(testRegion), Status: types.StringValue("status"), - ConnectionString: types.StringValue("connection_string"), + ConnectionString: types.StringNull(), }, true, }, @@ -206,6 +208,7 @@ func TestMapFieldsCreate(t *testing.T) { }, testRegion, resourceModel{ + Id: types.Int64Value(1), UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), diff --git a/stackit/internal/services/sqlserverflexalpha/user/resource.go b/stackit/internal/services/sqlserverflexalpha/user/resource.go index 41e6e1c5..a24cad8b 100644 --- a/stackit/internal/services/sqlserverflexalpha/user/resource.go +++ b/stackit/internal/services/sqlserverflexalpha/user/resource.go @@ -416,6 +416,7 @@ func mapFieldsCreate(userResp *sqlserverflexalpha.CreateUserResponse, model *res return fmt.Errorf("user id not present") } userId := *user.Id + model.Id = types.Int64Value(userId) model.UserId = types.Int64Value(userId) model.Username = types.StringPointerValue(user.Username) @@ -467,6 +468,7 @@ func mapFields(userResp *sqlserverflexalpha.GetUserResponse, model *resourceMode return fmt.Errorf("user id not present") } + model.Id = types.Int64Value(userId) model.UserId = types.Int64Value(userId) model.Username = types.StringPointerValue(user.Username) diff --git a/stackit/internal/wait/postgresflexalpha/wait.go b/stackit/internal/wait/postgresflexalpha/wait.go index 5177e6f1..c490b605 100644 --- a/stackit/internal/wait/postgresflexalpha/wait.go +++ b/stackit/internal/wait/postgresflexalpha/wait.go @@ -67,9 +67,11 @@ func CreateInstanceWaitHandler( if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil { return false, nil, nil } - tflog.Debug(ctx, "waiting for instance ready", map[string]interface{}{ - "status": *s.Status, - }) + tflog.Debug( + ctx, "waiting for instance ready", map[string]interface{}{ + "status": *s.Status, + }, + ) switch *s.Status { default: return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status) @@ -118,13 +120,13 @@ func CreateInstanceWaitHandler( instanceCreated = true instanceGetResponse = s case InstanceStateSuccess: - if *s.Network.AccessScope == "SNA" { - if s.Network == nil || s.Network.InstanceAddress == nil { + if s.Network != nil && s.Network.AccessScope != nil && *s.Network.AccessScope == "SNA" { + if s.Network.InstanceAddress == nil { tflog.Warn(ctx, "Waiting for instance_address") return false, nil, nil } if s.Network.RouterAddress == nil { - tflog.Info(ctx, "Waiting for router_address") + tflog.Warn(ctx, "Waiting for router_address") return false, nil, nil } } -- 2.49.1 From 6ee158f2e0a0b076657c22da5d831968bebc3ad1 Mon Sep 17 00:00:00 2001 From: Andre Harms Date: Tue, 10 Feb 2026 14:31:45 +0100 Subject: [PATCH 2/3] fix: remove unused files --- stackit/internal/services/postgresflexalpha/main.go | 1 - stackit/internal/services/sqlserverflexalpha/main.go | 1 - 2 files changed, 2 deletions(-) delete mode 100644 stackit/internal/services/postgresflexalpha/main.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/main.go diff --git a/stackit/internal/services/postgresflexalpha/main.go b/stackit/internal/services/postgresflexalpha/main.go deleted file mode 100644 index 5e20f208..00000000 --- a/stackit/internal/services/postgresflexalpha/main.go +++ /dev/null @@ -1 +0,0 @@ -package postgresflexalpha diff --git a/stackit/internal/services/sqlserverflexalpha/main.go b/stackit/internal/services/sqlserverflexalpha/main.go deleted file mode 100644 index 7ec38cdc..00000000 --- a/stackit/internal/services/sqlserverflexalpha/main.go +++ /dev/null @@ -1 +0,0 @@ -package sqlserverflexalpha -- 2.49.1 From aaebfbf634c8b38140a3e1fbe5ce8fc2b4c3be38 Mon Sep 17 00:00:00 2001 From: Andre Harms Date: Tue, 10 Feb 2026 17:02:19 +0100 Subject: [PATCH 3/3] fix: handle incomplete connection info in response --- .../postgresflexalpha/instance/functions.go | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/stackit/internal/services/postgresflexalpha/instance/functions.go b/stackit/internal/services/postgresflexalpha/instance/functions.go index 862f88ff..93fb544d 100644 --- a/stackit/internal/services/postgresflexalpha/instance/functions.go +++ b/stackit/internal/services/postgresflexalpha/instance/functions.go @@ -55,6 +55,22 @@ func mapGetInstanceResponseToModel( ) } + isConnectionInfoIncomplete := resp.ConnectionInfo == nil || + resp.ConnectionInfo.Host == nil || *resp.ConnectionInfo.Host == "" || + resp.ConnectionInfo.Port == nil || *resp.ConnectionInfo.Port == 0 + + if isConnectionInfoIncomplete { + m.ConnectionInfo = postgresflexalpharesource.NewConnectionInfoValueNull() + } else { + m.ConnectionInfo = postgresflexalpharesource.NewConnectionInfoValueMust( + postgresflexalpharesource.ConnectionInfoValue{}.AttributeTypes(ctx), + map[string]attr.Value{ + "host": types.StringPointerValue(resp.ConnectionInfo.Host), + "port": types.Int64PointerValue(resp.ConnectionInfo.Port), + }, + ) + } + m.ConnectionInfo.Host = types.StringValue("") if host, ok := resp.ConnectionInfo.GetHostOk(); ok { m.ConnectionInfo.Host = types.StringValue(host) @@ -138,8 +154,8 @@ func mapGetDataInstanceResponseToModel( ) error { m.BackupSchedule = types.StringValue(resp.GetBackupSchedule()) handleEncryption(m, resp) - m.ConnectionInfo.Host = types.StringValue(resp.ConnectionInfo.GetHost()) - m.ConnectionInfo.Port = types.Int64Value(resp.ConnectionInfo.GetPort()) + handleConnectionInfo(ctx, m, resp) + m.FlavorId = types.StringValue(resp.GetFlavorId()) m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString()) m.InstanceId = types.StringPointerValue(resp.Id) @@ -169,6 +185,24 @@ func mapGetDataInstanceResponseToModel( return nil } +func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) { + isConnectionInfoIncomplete := resp.ConnectionInfo == nil || + resp.ConnectionInfo.Host == nil || *resp.ConnectionInfo.Host == "" || + resp.ConnectionInfo.Port == nil || *resp.ConnectionInfo.Port == 0 + + if isConnectionInfoIncomplete { + m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueNull() + } else { + m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueMust( + postgresflexalphadatasource.ConnectionInfoValue{}.AttributeTypes(ctx), + map[string]attr.Value{ + "host": types.StringPointerValue(resp.ConnectionInfo.Host), + "port": types.Int64PointerValue(resp.ConnectionInfo.Port), + }, + ) + } +} + func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) error { netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl()) if diags.HasError() { -- 2.49.1