How to set env variables in atlantis config file?

For example, I want to set CONSUL_HTTP_TOKEN and CONSUL_TOKEN environment variables in atlantis’ config file:

workflow:
  staging:
    plan:
      steps:
        - env:
            name: CONSUL_HTTP_TOKEN
            command: 'echo "${CONSUL_HTTP_TOKEN_ID}"'
        - env:
            name: CONSUL_TOKEN
            command: 'echo "${CONSUL_TOKEN_ID}"'
        ...
        - init
        - plan

These environment variables are in the system level which running atlantis server:

  • CONSUL_HTTP_TOKEN_ID
  • CONSUL_TOKEN_ID

However, when I run atlantis plan, it can’t communicate with the real consul server. How to set the env correctly?

Did you find a way to set environment variables in atlantis plan files?

Your syntax looks correct according to the documentation Custom Workflows | Atlantis

Here is what is mostly working for me

repos.yaml

repos:
- id: /.*/
  delete_source_branch_on_merge: true
  allow_custom_workflows: false
  apply_requirements: [mergeable, approved]
  pre_workflow_hooks:
  - run: "/local/generate_atlantis.sh ${ATLANTIS_ENV}"
workflows:
  singlethreaded:
    plan:
      steps: 
      - env: 
          name: TF_CLI_ARGS_plan
          value: "-parallelism=1"
    apply:
      steps: 
      - env: 
          name: TF_CLI_ARGS_apply
          value: "-parallelism=1"

Though honestly using the built in extra_args would likely be a cleaner solution

# Example from https://www.runatlantis.io/docs/custom-workflows.html#use-cases
workflows:
  myworkflow:
    plan:
      steps:
      - init:
          extra_args: ["-lock=false"]
      - plan:
          extra_args: ["-lock=false"]
    apply:
      steps:
      - apply:
          extra_args: ["-lock=false"]

https://www.runatlantis.io/docs/custom-workflows.html#use-cases

1 Like