Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use = in the actual variable definition #208

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions internal/cmd/stack/local_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,35 +148,34 @@ type EnvironmentVariable struct {
Value graphql.String `json:"value"`
}

func parseEnvVariablesForLocalPreview(cliCtx *cli.Context) ([]EnvironmentVariable, error) {
envVars := make([]EnvironmentVariable, 0)

parseFn := func(ev string, mutateKey func(string) string) error {
parts := strings.Split(ev, "=")
if len(parts) != 2 {
return fmt.Errorf("invalid environment variable %q, must be in the form of KEY=VALUE", ev)
}
func parseEnvVar(env string, envVars []EnvironmentVariable, mutateKey func(string) string) ([]EnvironmentVariable, error) {
parts := strings.SplitN(env, "=", 2)
if len(parts) != 2 {
return envVars, fmt.Errorf("invalid environment variable %q, must be in the form of KEY=VALUE", env)
}

if mutateKey != nil {
parts[0] = mutateKey(parts[0])
}
if mutateKey != nil {
parts[0] = mutateKey(parts[0])
}

envVars = append(envVars, EnvironmentVariable{
Key: graphql.String(parts[0]),
Value: graphql.String(parts[1]),
})
return append(envVars, EnvironmentVariable{
Key: graphql.String(parts[0]),
Value: graphql.String(parts[1]),
}), nil
}

return nil
}
func parseEnvVariablesForLocalPreview(cliCtx *cli.Context) ([]EnvironmentVariable, error) {
envVars := make([]EnvironmentVariable, 0)

var err error
for _, ev := range cliCtx.StringSlice(flagOverrideEnvVars.Name) {
if err := parseFn(ev, nil); err != nil {
if envVars, err = parseEnvVar(ev, envVars, nil); err != nil {
return nil, err
}
}

for _, ev := range cliCtx.StringSlice(flagOverrideEnvVarsTF.Name) {
if err := parseFn(ev, func(s string) string {
if envVars, err = parseEnvVar(ev, envVars, func(s string) string {
return strings.Join([]string{"TF_", s}, "")
}); err != nil {
return nil, err
Expand Down