From aaebfbf634c8b38140a3e1fbe5ce8fc2b4c3be38 Mon Sep 17 00:00:00 2001 From: Andre Harms Date: Tue, 10 Feb 2026 17:02:19 +0100 Subject: [PATCH] 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() {