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

Allow passing custom arguments from Atlantis command to Atlantis.yaml - use case for custom init arguments. #113

Closed
mechastorm opened this issue Apr 24, 2018 · 1 comment
Milestone

Comments

@mechastorm
Copy link

Problem

This feature will help my team integrate our existing terraform projects with Atlantis with minimal changes.

We currently use the env/{env}.tfvars project structure with the addition of a env/{env}.backend.tfvars for unique remote backend configs per environments.

.
├── env
│   ├── production.tfvars
│   ├── production.backend.tfvars
│   ├── staging.tfvars
│   └── staging.backend.tfvars
└── main.tf

In our workflow, when we do terraform init, it will be

terraform init -backend-config=production.backend.tfvars

Currently Atlantis does not seem to able to support this structure.

Wish

Be able to initialize a custom backend config file from the atlantis command.

Suggestion

Utilizing the atlantis.yaml config, I could in theory have a config like

extra_arguments:
  - command_name: init
    arguments:
    - "-backend-config=env/${MY_ENV_NAME}.backend.tfvars "
  - command_name: plan
    arguments:
    - "-var-file=env/${MY_ENV_NAME}.tfvars "

Then in an MR/PR, I can run the atlantis command (in theory)

atlantis plan --extra-args="MY_ENV_NAME=staging"

I believe this feature would allow users extra flexibility as well in doing additional custom hooks with the atlantis.yaml config.

@lkysow
Copy link
Member

lkysow commented Jul 4, 2018

Closed by #152. In version 0.4 now.

To accomplish this you need to define each "project" in your repo in an atlantis.yaml file at the root and then create a separate workflow for staging/prod:

# atlantis.yaml
version: 2
projects:
- name: staging
  dir: .
  workflow: staging
- name: production
  dir: .
  workflow: production
workflows:
  production:
    plan:
      steps:
      - run: rm -rf .terraform # Otherwise terraform will get confused.
      - init:
          extra_args: [-backend-config=env/production.backend.tfvars]
      - plan:
          extra_args: [-var-file=env/production.tfvars]
  staging:
    plan:
      steps:
      - run: rm -rf .terraform
      - init:
          extra_args: [-backend-config=env/staging.backend.tfvars]
      - plan:
          extra_args: [-var-file=env/staging.tfvars]

Atlantis will automatically run plan now so you won't be needing this as much but to run plan for staging you need to use the project name and the -p flag:

atlantis plan -p staging

To apply:

atlantis apply -p staging

@lkysow lkysow closed this as completed Jul 4, 2018
meringu pushed a commit to meringu/atlantis that referenced this issue May 29, 2023
…ntis#113)

* Adding e2e tests back and upgrading terraform version 0.9.11

* Fixing the binary name for e2e tests

* revert binary name change

* missed indentation for makefile

* use owner name for branch head for pull request creation
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

No branches or pull requests

2 participants