fix: handle incomplete connection info in response
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 11s
CI Workflow / CI (pull_request) Failing after 18m5s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 34m35s
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 11s
CI Workflow / CI (pull_request) Failing after 18m5s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 34m35s
This commit is contained in:
parent
6ee158f2e0
commit
aaebfbf634
1 changed files with 36 additions and 2 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue