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

Write temp script instead of running with sh -c #337

Open
lkysow opened this issue Oct 30, 2018 · 6 comments
Open

Write temp script instead of running with sh -c #337

lkysow opened this issue Oct 30, 2018 · 6 comments
Labels
feature New functionality/enhancement Stale

Comments

@lkysow
Copy link
Member

lkysow commented Oct 30, 2018

Currently we run TF commands via sh -c "<cmds>" so that environment variables from the local environment can be used within additional args like -var mysecret=$SECRET.

The problem with this is that we need to manually escape what we pass in, which leads to problems like #302. Instead what we should do is write a temporary script and then execute that.

@majormoses
Copy link
Contributor

can we have it cat the debug script when in a debug mode? If there are issues it's super helpful to output what it attempted to do.

@kipkoan
Copy link
Contributor

kipkoan commented Oct 31, 2018 via email

@lkysow
Copy link
Member Author

lkysow commented Oct 31, 2018

@majormoses yeah some sort of debugging ability will be necessary. Right now it logs the exact command that it's running so we'd want something similar.

@kipkoan it uses exec: https://github.com/runatlantis/atlantis/blob/master/server/events/terraform/terraform_client.go#L119 The problem is that if you use exec without sh -c, if someone has config like:

workflows:
  custom:
    plan:
      steps:
      - init
      - plan:
         extra_args: [-var-file, $WORKSPACE.tfvars]

Then if you were doing exec.Command("terraform", "plan", "-var-file", "$WORKSPACE.tfvars") the environment variable wouldn't be used, it would use that string. So instead we do exec.Command("sh", "-c", "terraform plan -var-file $WORKSPACE.tfvars").

What I think is a better practice is to write a temp script:

#!/bin/sh
set -e
terraform plan -var-file $WORKSPACE.tfvars

@kipkoan
Copy link
Contributor

kipkoan commented Oct 31, 2018 via email

@tomer-1
Copy link

tomer-1 commented Nov 1, 2018

won't it be a problem if you'd like to pass secrets to the command? it will have to write the secrets to the machine...

@lkysow
Copy link
Member Author

lkysow commented Jan 9, 2019

This will also fix an issue where if terraform crashes, Atlantis isn't left hanging.

I think this is related to golang/go#18874

@lkysow lkysow added the feature New functionality/enhancement label Apr 4, 2019
@dosubot dosubot bot added the Stale label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement Stale
Projects
None yet
Development

No branches or pull requests

4 participants