fix: do not quote stringy env variables ()

This commit is contained in:
Cian Johnston 2024-08-08 14:34:55 +01:00 committed by GitHub
parent 72ddd72815
commit d30006a40b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -595,14 +595,16 @@ func extractEnvbuilderFromImage(ctx context.Context, imgRef, destPath string) er
// Check IsUnknown() first before calling String().
type stringable interface {
IsUnknown() bool
IsNull() bool
String() string
}
func appendKnownEnvToList(list types.List, key string, value stringable) types.List {
if value.IsUnknown() {
if value.IsUnknown() || value.IsNull() {
return list
}
elem := types.StringValue(fmt.Sprintf("%s=%s", key, value.String()))
val := strings.Trim(value.String(), `"`)
elem := types.StringValue(fmt.Sprintf("%s=%s", key, val))
list, _ = types.ListValue(types.StringType, append(list.Elements(), elem))
return list
}

View file

@ -92,9 +92,9 @@ func TestAccCachedImageDataSource(t *testing.T) {
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "exists", "true"),
resource.TestCheckResourceAttrSet("envbuilder_cached_image.test", "image"),
resource.TestCheckResourceAttrWith("envbuilder_cached_image.test", "image", quotedPrefix(deps.CacheRepo)),
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.0", "FOO=\"bar\""),
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.1", fmt.Sprintf("ENVBUILDER_CACHE_REPO=%q", deps.CacheRepo)),
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.2", fmt.Sprintf("ENVBUILDER_GIT_URL=%q", deps.Repo.URL)),
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.0", "FOO=bar"),
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.1", fmt.Sprintf("ENVBUILDER_CACHE_REPO=%s", deps.CacheRepo)),
resource.TestCheckResourceAttr("envbuilder_cached_image.test", "env.2", fmt.Sprintf("ENVBUILDER_GIT_URL=%s", deps.Repo.URL)),
),
},
// Should produce an empty plan after apply