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

Implement BASH_ENV functionality to share env vars between steps. #370

Closed
lkysow opened this issue Dec 3, 2018 · 2 comments · Fixed by #751
Closed

Implement BASH_ENV functionality to share env vars between steps. #370

lkysow opened this issue Dec 3, 2018 · 2 comments · Fixed by #751
Labels
feature New functionality/enhancement

Comments

@lkysow
Copy link
Member

lkysow commented Dec 3, 2018

Problem

There is currently no way to share environment variables in between steps (see #369). This is useful for users that want to source secrets from custom scripts and use them in terraform.

Solution

To achieve this, we should implement $BASH_ENV type functionality where users can write export statements to the file described by $BASH_ENV which gets source'd at each step:

- run: "echo export TEST=abc >> $BASH_ENV"
- run: "echo $BASH_ENV"
- run: "echo $TEST"

This would result in:

/tmp/kajsldjflksjdljk.sh
abc

Implementation

  • Generate a random file for each set of steps
  • source that file in each step before executing the actual step code

Notes

@ttk
Copy link

ttk commented Nov 27, 2020

The env step option to setup environment variables doesn't quite solve the use case when you have a single command that generates multiple environment variable exports that you want to source to to next step. The original proposal using $BASH_ENV would have been a more flexible option:

- run: "multiple-exports-creds.sh >> $BASH_ENV"

In my case the multiple-exports-creds.sh creates multiple environment variables in one go, whereas env command step option only creates one environment variable at a time. Any workarounds?

@ricardosilva86
Copy link

When I need to run TF apply in different environment, I usually export the GOOGLE_APPLICATION_CREDENTIALS env variable. Something like:

terragrunt-non-production:
    plan:
      steps:
      - env:
          name: GOOGLE_APPLICATION_CREDENTIALS
          value: /home/atlantis/.creds/key-non-prod.json
      - env:
          # Reduce Terraform suggestion output
          name: TF_IN_AUTOMATION
          value: 'true'
      - run: terragrunt plan -input=false -out=$PLANFILE
      - run: terragrunt show -json $PLANFILE > $SHOWFILE

Shouldn't be like this? after reading this, it looks like I should be using terraform workspaces. Can someone comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants