chore(iaas): extract mapping of labels into util func (#867)

This commit is contained in:
Ruben Hönle 2025-06-05 13:46:33 +02:00 committed by GitHub
parent ad24ebe52d
commit 281d31f615
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 156 additions and 171 deletions

View file

@ -8,7 +8,6 @@ import (
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@ -326,20 +325,11 @@ func mapFields(ctx context.Context, keyPairResp *iaas.Keypair, model *Model) err
model.PublicKey = types.StringPointerValue(keyPairResp.PublicKey)
model.Fingerprint = types.StringPointerValue(keyPairResp.Fingerprint)
labels, diags := types.MapValueFrom(ctx, types.StringType, map[string]interface{}{})
if diags.HasError() {
return fmt.Errorf("converting labels to StringValue map: %w", core.DiagsToError(diags))
var err error
model.Labels, err = iaasUtils.MapLabels(ctx, keyPairResp.Labels, model.Labels)
if err != nil {
return err
}
if keyPairResp.Labels != nil && len(*keyPairResp.Labels) != 0 {
var diags diag.Diagnostics
labels, diags = types.MapValueFrom(ctx, types.StringType, *keyPairResp.Labels)
if diags.HasError() {
return fmt.Errorf("converting labels to StringValue map: %w", core.DiagsToError(diags))
}
} else if model.Labels.IsNull() {
labels = types.MapNull(types.StringType)
}
model.Labels = labels
return nil
}