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

Extra arguments environment variables #150

Merged
merged 11 commits into from
Sep 25, 2017

Conversation

anubhavmishra
Copy link
Collaborator

  • You can now use ${ENVIRONMENT}, ${ATLANTIS_TERRAFORM_VERSION} and ${WORKSPACE} in extra_arguments section in atlantis.yaml project config file.

@codecov-io
Copy link

codecov-io commented Sep 24, 2017

Codecov Report

Merging #150 into master will decrease coverage by 5.62%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #150      +/-   ##
==========================================
- Coverage   37.27%   31.64%   -5.63%     
==========================================
  Files          16       17       +1     
  Lines        1261     1485     +224     
==========================================
  Hits          470      470              
- Misses        773      997     +224     
  Partials       18       18
Impacted Files Coverage Δ
server/plan_executor.go 11.25% <0%> (ø) ⬆️
server/apply_executor.go 0% <0%> (ø) ⬆️
server/server.go 0% <0%> (ø) ⬆️
server/bindata_assetfs.go 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbbd59d...db31eda. Read the comment docs.

server/utils.go Outdated

// populateRuntimeEnvironmentVariables populates the terraform extra vars specified in the project config file
// with atlantis specific environment variables
func populateRuntimeEnvironmentVariables(extraArgs []string, workspaceDir string, tfEnv string, tfVersion *version.Version) []string {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the function that replaces the arguments for both plan_executor.go and apply_executor.go.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We've been using object-oriented style functions throughout the codebase so I think we should stick with that for now. That means associating this method with an actual struct.

server/utils.go Outdated
@@ -0,0 +1,22 @@
package server
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added utils.go to be used for functions like these.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this doesn't belong in a server util. It is used for the execution so can we not put it in a command runner? Util classes should be reserved for the most generic of functions. Otherwise it just becomes a dumping ground. This function doesn't strike me as generic enough.

@lkysow
Copy link
Collaborator

lkysow commented Sep 24, 2017

I have some feedback on the exact code changes but my first question is why we're doing string substitution instead of using the shell to do the interpretation itself. This seems a lot safer?

	cmd := exec.Command("bash", "-c", "echo bye $TEST")
	env := os.Environ()
	env = append(env, "TEST=hi")
	cmd.Env = env
	out, err := cmd.CombinedOutput()
	fmt.Printf("out: %v, err: %v", string(out), err)

If we do bash -c or sh -c then it does the interpolation properly

@anubhavmishra
Copy link
Collaborator Author

This requires you to read the OS environment variables and then pass that down with the exec func. That seemed hacky that is why I didn't want to do it. But sure, I can put that back.

@lkysow
Copy link
Collaborator

lkysow commented Sep 24, 2017 via email

Copy link
Collaborator

@lkysow lkysow left a comment

Choose a reason for hiding this comment

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

That really does clean up the code. If you're good with it then I'm good. I was thinking that maybe it was overkill to run with bash -c. There are definitely some security problems with this now since you could close out the quote and then execute anything you wanted. We should add a security section to our README.

@@ -52,14 +53,31 @@ func (c *Client) Version() *version.Version {

// RunCommandWithVersion executes the provided version of terraform with
// the provided args in path.
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should document what v and env do in the docs here

// append terraform executable name with args
tfCmd := fmt.Sprintf("%s %s", tfExecutable, strings.Join(args, " "))

terraformCmd := exec.Command("bash", "-c", tfCmd)
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we use bash or sh?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think sh....

@lkysow
Copy link
Collaborator

lkysow commented Sep 25, 2017

Want to look at tests for this after?

@anubhavmishra anubhavmishra force-pushed the extra-arguments-environment-variables branch from 4c06e92 to db31eda Compare September 25, 2017 18:45
@anubhavmishra anubhavmishra merged commit 464cb2f into master Sep 25, 2017
@anubhavmishra anubhavmishra deleted the extra-arguments-environment-variables branch September 25, 2017 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants