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

fix: Update multienv_step_runner Env Var Parsing Logic (#2351) #2354

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion server/core/runtime/multienv_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (r *MultiEnvStepRunner) Run(ctx command.ProjectContext, command string, pat
var sb strings.Builder
sb.WriteString("Dynamic environment variables added:\n")
for _, item := range envVars {
nameValue := strings.Split(item, "=")
nameValue := strings.SplitN(item, "=", 2)
if len(nameValue) == 2 {
envs[nameValue[0]] = nameValue[1]
sb.WriteString(nameValue[0])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also finding that this list of dynamic env vars added is quite noisy, and doesn't really add much value to plans/applies. Would there be any openness to suppressing this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tapaszto is the original developer, maybe he can chime in why this is here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use multienv step to add dynamic number of environment variables coming from the result of a webservice call.
Originally we proposed to have a json string which can be parsed safely and handling the errors coming from the runstep result but later the reviewer suggested to have a simple key/value list. We modified accordingly implementing the simplest solution for our requirements and did not assume having "=" in the envvar values.
Here is the PR containing more details of our use case:
#1793

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback @tapaszto.

@jamengual As it stands, is this a reasonable bug fix to incorporate into the mainline? I think it's probably a pretty common case for env vars to contain =, as in my experience they're often base64 encoded.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if @tapaszto agrees that this is ok to add and does not change the use case I think it will be ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe we should update the docs if they do not explain well the use case and or the key=value structure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if @tapaszto agrees that this is ok to add and does not change the use case I think it will be ok.

It's ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@austinsherron check the docs and see if they will need adjustment due to this change, please.
We can merge it after

Expand Down
10 changes: 10 additions & 0 deletions server/core/runtime/multienv_step_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func TestMultiEnvStepRunner_Run(t *testing.T) {
ExpOut: "Dynamic environment variables added:\nTF_VAR_REPODEFINEDVARIABLE_ONE\n",
Version: "v1.2.3",
},
{
Command: `echo 'TF_VAR_REPODEFINEDVARIABLE_TWO=value=1='`,
ExpOut: "Dynamic environment variables added:\nTF_VAR_REPODEFINEDVARIABLE_TWO\n",
Version: "v1.2.3",
},
{
Command: `echo 'TF_VAR_REPODEFINEDVARIABLE_NO_VALUE'`,
ExpErr: "Invalid environment variable definition: TF_VAR_REPODEFINEDVARIABLE_NO_VALUE",
Version: "v1.2.3",
},
}
RegisterMockTestingT(t)
tfClient := mocks.NewMockClient()
Expand Down