Skip to content

Commit d30006a

Browse files
authored
fix: do not quote stringy env variables (#21)
1 parent 72ddd72 commit d30006a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

internal/provider/cached_image_resource.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,16 @@ func extractEnvbuilderFromImage(ctx context.Context, imgRef, destPath string) er
595595
// Check IsUnknown() first before calling String().
596596
type stringable interface {
597597
IsUnknown() bool
598+
IsNull() bool
598599
String() string
599600
}
600601

601602
func appendKnownEnvToList(list types.List, key string, value stringable) types.List {
602-
if value.IsUnknown() {
603+
if value.IsUnknown() || value.IsNull() {
603604
return list
604605
}
605-
elem := types.StringValue(fmt.Sprintf("%s=%s", key, value.String()))
606+
val := strings.Trim(value.String(), `"`)
607+
elem := types.StringValue(fmt.Sprintf("%s=%s", key, val))
606608
list, _ = types.ListValue(types.StringType, append(list.Elements(), elem))
607609
return list
608610
}

internal/provider/cached_image_resource_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ func TestAccCachedImageDataSource(t *testing.T) {
9292
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "exists", "true"),
9393
resource.TestCheckResourceAttrSet("envbuilder_cached_image.test", "image"),
9494
resource.TestCheckResourceAttrWith("envbuilder_cached_image.test", "image", quotedPrefix(deps.CacheRepo)),
95-
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.0", "FOO=\"bar\""),
96-
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.1", fmt.Sprintf("ENVBUILDER_CACHE_REPO=%q", deps.CacheRepo)),
97-
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.2", fmt.Sprintf("ENVBUILDER_GIT_URL=%q", deps.Repo.URL)),
95+
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.0", "FOO=bar"),
96+
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.1", fmt.Sprintf("ENVBUILDER_CACHE_REPO=%s", deps.CacheRepo)),
97+
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.2", fmt.Sprintf("ENVBUILDER_GIT_URL=%s", deps.Repo.URL)),
9898
),
9999
},
100100
// Should produce an empty plan after apply

0 commit comments

Comments
 (0)