diff --git a/internal/common/map.go b/internal/common/map.go index dd678fd..8e11724 100644 --- a/internal/common/map.go +++ b/internal/common/map.go @@ -8,7 +8,7 @@ import ( ) func MapFrom(values map[string]any, ctx context.Context, d diag.Diagnostics) types.Map { - if len(values) == 0 { + if values == nil { return types.MapNull(types.StringType) } diff --git a/internal/resource/infrastructure_stack_schema.go b/internal/resource/infrastructure_stack_schema.go index 1b60c05..32a28c5 100644 --- a/internal/resource/infrastructure_stack_schema.go +++ b/internal/resource/infrastructure_stack_schema.go @@ -6,10 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" @@ -156,7 +157,7 @@ func (r *InfrastructureStackResource) schema() schema.Schema { ElementType: types.StringType, Optional: true, Computed: true, - PlanModifiers: []planmodifier.Map{mapplanmodifier.UseStateForUnknown()}, + Default: mapdefault.StaticValue(types.MapValueMust(types.StringType, map[string]attr.Value{})), Validators: []validator.Map{mapvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("raw"))}, }, "annotations": schema.MapAttribute{ @@ -165,7 +166,7 @@ func (r *InfrastructureStackResource) schema() schema.Schema { ElementType: types.StringType, Optional: true, Computed: true, - PlanModifiers: []planmodifier.Map{mapplanmodifier.UseStateForUnknown()}, + Default: mapdefault.StaticValue(types.MapValueMust(types.StringType, map[string]attr.Value{})), Validators: []validator.Map{mapvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("raw"))}, }, "service_account": schema.StringAttribute{