Skip to content

Commit 37a1f94

Browse files
Normalize null value for Images to [] for consistent behavior
1 parent 920e625 commit 37a1f94

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

linode/producerimagesharegroup/framework_models.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package producerimagesharegroup
22

33
import (
44
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
5+
"github.com/hashicorp/terraform-plugin-framework/attr"
56
"github.com/hashicorp/terraform-plugin-framework/diag"
67
"github.com/hashicorp/terraform-plugin-framework/types"
78
"github.com/linode/linodego"
@@ -54,8 +55,11 @@ func (data *ResourceModel) FlattenImageShareGroup(
5455
// Images must persist in state across CRUD operations but is not returned by the API. It will be maintained
5556
// manually as a part of Create, Update, and Read, so we only need to set it here if it is null so that it is
5657
// properly typed.
57-
if data.Images.IsNull() {
58-
data.Images = types.ListNull(imageShareGroupImage.Type())
58+
//if data.Images.IsNull() {
59+
// data.Images = types.ListNull(imageShareGroupImage.Type())
60+
//}
61+
if data.Images.IsNull() || data.Images.IsUnknown() {
62+
data.Images = types.ListValueMust(imageShareGroupImage.Type(), []attr.Value{})
5963
}
6064
}
6165

linode/producerimagesharegroup/framework_resource.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package producerimagesharegroup
33
import (
44
"context"
55
"fmt"
6+
"github.com/hashicorp/terraform-plugin-framework/attr"
67

78
"github.com/hashicorp/terraform-plugin-framework/resource"
89
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -164,6 +165,11 @@ func (r *Resource) Read(
164165

165166
state.Images = listVal
166167

168+
// Normalize null/unknown -> []
169+
if state.Images.IsNull() || state.Images.IsUnknown() {
170+
state.Images = types.ListValueMust(imageShareGroupImage.Type(), []attr.Value{})
171+
}
172+
167173
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
168174
}
169175

@@ -373,6 +379,11 @@ func (r *Resource) Update(
373379
}
374380
state.Images = listVal
375381

382+
// Normalize null/unknown -> []
383+
if state.Images.IsNull() || state.Images.IsUnknown() {
384+
state.Images = types.ListValueMust(imageShareGroupImage.Type(), []attr.Value{})
385+
}
386+
376387
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
377388
}
378389

linode/producerimagesharegroup/framework_schema_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
55
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
66
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
7+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
78
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
89
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
910
)
@@ -79,7 +80,11 @@ var frameworkResourceSchema = schema.Schema{
7980
"images": schema.ListNestedAttribute{
8081
Description: "The images to be shared using this Image Share Group.",
8182
Optional: true,
83+
Computed: true,
8284
NestedObject: imageShareGroupImage,
85+
PlanModifiers: []planmodifier.List{
86+
listplanmodifier.UseStateForUnknown(),
87+
},
8388
},
8489
},
8590
}

0 commit comments

Comments
 (0)