Skip to content

Commit 3c2e869

Browse files
committed
s/data source/resource/g again
1 parent 46a456f commit 3c2e869

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

internal/provider/cached_image_resource.go

+26-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ 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/mapplanmodifier"
31+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
32+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
3033
"github.com/hashicorp/terraform-plugin-framework/types"
3134
"github.com/hashicorp/terraform-plugin-log/tflog"
3235
)
@@ -38,7 +41,7 @@ func NewCachedImageResource() resource.Resource {
3841
return &CachedImageResource{}
3942
}
4043

41-
// CachedImageResource defines the data source implementation.
44+
// CachedImageResource defines the resource implementation.
4245
type CachedImageResource struct {
4346
client *http.Client
4447
}
@@ -92,14 +95,23 @@ func (r *CachedImageResource) Schema(ctx context.Context, req resource.SchemaReq
9295
"builder_image": schema.StringAttribute{
9396
MarkdownDescription: "The envbuilder image to use if the cached version is not found.",
9497
Required: true,
98+
PlanModifiers: []planmodifier.String{
99+
stringplanmodifier.RequiresReplace(),
100+
},
95101
},
96102
"cache_repo": schema.StringAttribute{
97103
MarkdownDescription: "(Envbuilder option) The name of the container registry to fetch the cache image from.",
98104
Required: true,
105+
PlanModifiers: []planmodifier.String{
106+
stringplanmodifier.RequiresReplace(),
107+
},
99108
},
100109
"git_url": schema.StringAttribute{
101110
MarkdownDescription: "(Envbuilder option) The URL of a Git repository containing a Devcontainer or Docker image to clone.",
102111
Required: true,
112+
PlanModifiers: []planmodifier.String{
113+
stringplanmodifier.RequiresReplace(),
114+
},
103115
},
104116
// Optional "inputs".
105117
"base_image_cache_dir": schema.StringAttribute{
@@ -117,14 +129,23 @@ func (r *CachedImageResource) Schema(ctx context.Context, req resource.SchemaReq
117129
"devcontainer_dir": schema.StringAttribute{
118130
MarkdownDescription: "(Envbuilder option) The path to the folder containing the devcontainer.json file that will be used to build the workspace and can either be an absolute path or a path relative to the workspace folder. If not provided, defaults to `.devcontainer`.",
119131
Optional: true,
132+
PlanModifiers: []planmodifier.String{
133+
stringplanmodifier.RequiresReplace(),
134+
},
120135
},
121136
"devcontainer_json_path": schema.StringAttribute{
122137
MarkdownDescription: "(Envbuilder option) The path to a devcontainer.json file that is either an absolute path or a path relative to DevcontainerDir. This can be used in cases where one wants to substitute an edited devcontainer.json file for the one that exists in the repo.",
123138
Optional: true,
139+
PlanModifiers: []planmodifier.String{
140+
stringplanmodifier.RequiresReplace(),
141+
},
124142
},
125143
"dockerfile_path": schema.StringAttribute{
126144
MarkdownDescription: "(Envbuilder option) The relative path to the Dockerfile that will be used to build the workspace. This is an alternative to using a devcontainer that some might find simpler.",
127145
Optional: true,
146+
PlanModifiers: []planmodifier.String{
147+
stringplanmodifier.RequiresReplace(),
148+
},
128149
},
129150
"docker_config_base64": schema.StringAttribute{
130151
MarkdownDescription: "(Envbuilder option) The base64 encoded Docker config file that will be used to pull images from private container registries.",
@@ -139,6 +160,9 @@ func (r *CachedImageResource) Schema(ctx context.Context, req resource.SchemaReq
139160
MarkdownDescription: "Extra environment variables to set for the container. This may include envbuilder options.",
140161
ElementType: types.StringType,
141162
Optional: true,
163+
PlanModifiers: []planmodifier.Map{
164+
mapplanmodifier.RequiresReplace(),
165+
},
142166
},
143167
"fallback_image": schema.StringAttribute{
144168
MarkdownDescription: "(Envbuilder option) Specifies an alternative image to use when neither an image is declared in the devcontainer.json file nor a Dockerfile is present. If there's a build failure (from a faulty Dockerfile) or a misconfiguration, this image will be the substitute. Set ExitOnBuildFailure to true to halt the container if the build faces an issue.",
@@ -227,7 +251,7 @@ func (r *CachedImageResource) Configure(ctx context.Context, req resource.Config
227251

228252
if !ok {
229253
resp.Diagnostics.AddError(
230-
"Unexpected Data Source Configure Type",
254+
"Unexpected Resource Configure Type",
231255
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
232256
)
233257

@@ -416,8 +440,6 @@ func (r *CachedImageResource) runCacheProbe(ctx context.Context, data CachedImag
416440
tflog.Debug(ctx, "workspace_folder not specified, using temp dir", map[string]any{"workspace_folder": workspaceFolder})
417441
}
418442

419-
// TODO: check if this is a "plan" or "apply", and only run envbuilder on "apply".
420-
// This may require changing this to be a resource instead of a data source.
421443
opts := eboptions.Options{
422444
// These options are always required
423445
CacheRepo: data.CacheRepo.ValueString(),

0 commit comments

Comments
 (0)