chore(iaas): extract mapping of labels into util func (#867)
This commit is contained in:
parent
ad24ebe52d
commit
281d31f615
15 changed files with 156 additions and 171 deletions
|
|
@ -10,7 +10,6 @@ import (
|
|||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"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"
|
||||
|
|
@ -358,18 +357,9 @@ func mapFields(ctx context.Context, securityGroupResp *iaas.SecurityGroup, model
|
|||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
|
||||
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))
|
||||
}
|
||||
if securityGroupResp.Labels != nil && len(*securityGroupResp.Labels) != 0 {
|
||||
var diags diag.Diagnostics
|
||||
labels, diags = types.MapValueFrom(ctx, types.StringType, *securityGroupResp.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)
|
||||
labels, err := iaasUtils.MapLabels(ctx, securityGroupResp.Labels, model.Labels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
model.SecurityGroupId = types.StringValue(securityGroupId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue