fix: refactor publish command (#14)
Some checks failed
Publish / Check GoReleaser config (push) Successful in 5s
Release / goreleaser (push) Failing after 27s
Publish / Publish provider (push) Failing after 4m4s

feat: add connection info

fix: prevent postgresql from failing when encryption is empty

## Description

<!-- **Please link some issue here describing what you are trying to achieve.**

In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->

relates to #1234

## Checklist

- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)

Reviewed-on: #14
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
Marcel_Henselin 2026-01-30 10:15:49 +00:00 committed by Marcel_Henselin
parent 5ec2ab8c67
commit a9df5b0ff5
Signed by: tf-provider.git.onstackit.cloud
GPG key ID: 6D7E8A1ED8955A9C
8 changed files with 650 additions and 425 deletions

View file

@ -15,7 +15,7 @@ import (
)
func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalpharesource.InstanceModel, resp *postgresflex.GetInstanceResponse) error {
tflog.Info(ctx, ">>>> MSH DEBUG <<<<", map[string]interface{}{
tflog.Debug(ctx, ">>>> MSH DEBUG <<<<", map[string]interface{}{
"id": m.Id.ValueString(),
"instance_id": m.InstanceId.ValueString(),
"backup_schedule": m.BackupSchedule.ValueString(),
@ -47,17 +47,17 @@ func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalphareso
},
)
}
m.ConnectionInfo.Host = types.StringValue(resp.ConnectionInfo.GetHost())
m.ConnectionInfo.Port = types.Int64Value(resp.ConnectionInfo.GetPort())
m.FlavorId = types.StringValue(resp.GetFlavorId())
if m.Id.IsNull() || m.Id.IsUnknown() {
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
}
m.InstanceId = types.StringPointerValue(resp.Id)
//m.IsDeletable = types.BoolUnknown()
//if isDel, ok := resp.GetIsDeletableOk(); ok {
// m.IsDeletable = types.BoolValue(isDel)
m.IsDeletable = types.BoolValue(resp.GetIsDeletable())
//}
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
if diags.HasError() {
@ -93,10 +93,6 @@ func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalphareso
m.Name = types.StringValue(resp.GetName())
//m.Status = types.StringUnknown()
//if status, ok := resp.GetStatusOk(); ok {
// m.Status = types.StringValue(string(status))
//}
m.Status = types.StringValue(string(resp.GetStatus()))
storage, diags := postgresflexalpharesource.NewStorageValue(
@ -117,13 +113,14 @@ func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalphareso
func mapGetDataInstanceResponseToModel(ctx context.Context, m *postgresflexalphadatasource.InstanceModel, resp *postgresflex.GetInstanceResponse) error {
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
//nolint:gocritic
// m.Encryption = postgresflexalpharesource.EncryptionValue{
// KekKeyId: types.StringValue(resp.Encryption.GetKekKeyId()),
// KekKeyRingId: types.StringValue(resp.Encryption.GetKekKeyRingId()),
// KekKeyVersion: types.StringValue(resp.Encryption.GetKekKeyVersion()),
// ServiceAccount: types.StringValue(resp.Encryption.GetServiceAccount()),
// }
m.Encryption = postgresflexalphadatasource.EncryptionValue{
KekKeyId: types.StringValue(resp.Encryption.GetKekKeyId()),
KekKeyRingId: types.StringValue(resp.Encryption.GetKekKeyRingId()),
KekKeyVersion: types.StringValue(resp.Encryption.GetKekKeyVersion()),
ServiceAccount: types.StringValue(resp.Encryption.GetServiceAccount()),
}
m.ConnectionInfo.Host = types.StringValue(resp.ConnectionInfo.GetHost())
m.ConnectionInfo.Port = types.Int64Value(resp.ConnectionInfo.GetPort())
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)

View file

@ -247,16 +247,20 @@ func (r *instanceResource) Create(
}
func modelToCreateInstancePayload(netAcl []string, model postgresflexalpha.InstanceModel, replVal int32) postgresflex.CreateInstanceRequestPayload {
payload := postgresflex.CreateInstanceRequestPayload{
BackupSchedule: model.BackupSchedule.ValueStringPointer(),
Encryption: &postgresflex.InstanceEncryption{
var enc postgresflex.InstanceEncryption
if !model.Encryption.IsNull() && !model.Encryption.IsUnknown() {
enc = postgresflex.InstanceEncryption{
KekKeyId: model.Encryption.KekKeyId.ValueStringPointer(),
KekKeyRingId: model.Encryption.KekKeyRingId.ValueStringPointer(),
KekKeyVersion: model.Encryption.KekKeyVersion.ValueStringPointer(),
ServiceAccount: model.Encryption.ServiceAccount.ValueStringPointer(),
},
FlavorId: model.FlavorId.ValueStringPointer(),
Name: model.Name.ValueStringPointer(),
}
}
payload := postgresflex.CreateInstanceRequestPayload{
BackupSchedule: model.BackupSchedule.ValueStringPointer(),
Encryption: &enc,
FlavorId: model.FlavorId.ValueStringPointer(),
Name: model.Name.ValueStringPointer(),
Network: &postgresflex.InstanceNetwork{
AccessScope: postgresflex.InstanceNetworkGetAccessScopeAttributeType(
model.Network.AccessScope.ValueStringPointer(),