Skip to content

Commit f817274

Browse files
committed
set image = builder_image if not exists
1 parent 1cfe12d commit f817274

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

internal/provider/cached_image_data_source.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (d *CachedImageDataSource) Schema(ctx context.Context, req datasource.Schem
174174
Optional: true,
175175
},
176176
"image": schema.StringAttribute{
177-
MarkdownDescription: "Outputs the cached image URL if it exists, otherwise the builder image URL is output instead.",
177+
MarkdownDescription: "Outputs the cached image URL if it exists, otherwise the builder image URL as output instead.",
178178
Computed: true,
179179
},
180180
"insecure": schema.BoolAttribute{
@@ -302,6 +302,8 @@ func (d *CachedImageDataSource) Read(ctx context.Context, req datasource.ReadReq
302302
data.Exists = types.BoolValue(err == nil)
303303
if err != nil {
304304
resp.Diagnostics.AddWarning("Cached image not found", err.Error())
305+
// TODO: Get the repo digest of the envbuilder image and use that as the ID
306+
data.Image = data.BuilderImage
305307
} else {
306308
digest, err := image.Digest()
307309
if err != nil {

internal/provider/cached_image_data_source_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ func TestAccCachedImageDataSource(t *testing.T) {
104104
resource.TestCheckResourceAttr("data.envbuilder_cached_image.test", "cache_repo", deps.CacheRepo),
105105
resource.TestCheckResourceAttr("data.envbuilder_cached_image.test", "extra_env.FOO", "bar"),
106106
resource.TestCheckResourceAttr("data.envbuilder_cached_image.test", "git_url", deps.RepoDir),
107+
resource.TestCheckResourceAttr("data.envbuilder_cached_image.test", "exists", "false"),
108+
resource.TestCheckResourceAttr("data.envbuilder_cached_image.test", "image", deps.BuilderImage),
107109
// Should be empty
108110
resource.TestCheckNoResourceAttr("data.envbuilder_cached_image.test", "git_username"),
109111
resource.TestCheckNoResourceAttr("data.envbuilder_cached_image.test", "git_password"),
110112
resource.TestCheckNoResourceAttr("data.envbuilder_cached_image.test", "cache_ttl_days"),
111113
// Computed values should be empty.
112114
resource.TestCheckNoResourceAttr("data.envbuilder_cached_image.test", "id"),
113-
resource.TestCheckResourceAttr("data.envbuilder_cached_image.test", "exists", "false"),
114-
resource.TestCheckNoResourceAttr("data.envbuilder_cached_image.test", "image"),
115115
resource.TestCheckResourceAttrSet("data.envbuilder_cached_image.test", "env.0"),
116116
),
117117
},

0 commit comments

Comments
 (0)