Skip to content

Commit 78c46c1

Browse files
committed
add plan modifiers
1 parent 3c2e869 commit 78c46c1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

internal/provider/cached_image_resource.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727

2828
"github.com/hashicorp/terraform-plugin-framework/resource"
2929
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
30+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
31+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
3032
"github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier"
3133
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
3234
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -224,18 +226,30 @@ func (r *CachedImageResource) Schema(ctx context.Context, req resource.SchemaReq
224226
ElementType: types.StringType,
225227
Computed: true,
226228
Sensitive: true,
229+
PlanModifiers: []planmodifier.List{
230+
listplanmodifier.RequiresReplace(),
231+
},
227232
},
228233
"exists": schema.BoolAttribute{
229234
MarkdownDescription: "Whether the cached image was exists or not for the given config.",
230235
Computed: true,
236+
PlanModifiers: []planmodifier.Bool{
237+
boolplanmodifier.RequiresReplace(),
238+
},
231239
},
232240
"id": schema.StringAttribute{
233241
MarkdownDescription: "Cached image identifier. This will generally be the image's SHA256 digest.",
234242
Computed: true,
243+
PlanModifiers: []planmodifier.String{
244+
stringplanmodifier.RequiresReplace(),
245+
},
235246
},
236247
"image": schema.StringAttribute{
237248
MarkdownDescription: "Outputs the cached image repo@digest if it exists, and builder image otherwise.",
238249
Computed: true,
250+
PlanModifiers: []planmodifier.String{
251+
stringplanmodifier.RequiresReplace(),
252+
},
239253
},
240254
},
241255
}
@@ -273,6 +287,7 @@ func (r *CachedImageResource) Read(ctx context.Context, req resource.ReadRequest
273287
// If the previous state is that Image == BuilderImage, then we previously did
274288
// not find the image. We will need to run another cache probe.
275289
if data.Image.Equal(data.BuilderImage) {
290+
tflog.Debug(ctx, "Image previously not found. Recreating.", map[string]any{"ref": data.Image.ValueString()})
276291
resp.State.RemoveResource(ctx)
277292
return
278293
}
@@ -284,9 +299,9 @@ func (r *CachedImageResource) Read(ctx context.Context, req resource.ReadRequest
284299
resp.Diagnostics.AddError("Error checking remote image", err.Error())
285300
return
286301
}
287-
tflog.Debug(ctx, "Remote image does not exist", map[string]any{"ref": data.Image.ValueString()})
288302
// Image does not exist any longer! Remove the resource so we can re-create
289303
// it next time.
304+
tflog.Debug(ctx, "Remote image does not exist any longer. Recreating.", map[string]any{"ref": data.Image.ValueString()})
290305
resp.State.RemoveResource(ctx)
291306
return
292307
}

0 commit comments

Comments
 (0)