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

Documentation clarification around multiple projects. #12

Closed
powellchristoph opened this issue Feb 19, 2018 · 8 comments
Closed

Documentation clarification around multiple projects. #12

powellchristoph opened this issue Feb 19, 2018 · 8 comments

Comments

@powellchristoph
Copy link

Greetings,

I have started diving into Terraform and Atlantis. One issue that isn't very clear is how Atlantis supports the multiple "projects" repository layout and separate state files for each.

I want this layout with each "project" having its own state file.

.
├── staging
│   ├── main.tf
|   └── ...
└── production
│   ├── main.tf
|   └── ...
└── modules
    ├── module_1
    └── ...

I can't tell from the documentation how Atlantis will handle it if at all. If it does, how does this work with a backend for each to separate the state files?

@lkysow
Copy link
Member

lkysow commented Feb 19, 2018

If you make a change to staging/main.tf or any other file in that directory Atlantis will identify that it needs to run plan in staging/ and will do so.

In terms of backends, under the hood all Atlantis does is basically cd staging && terraform plan so as long as you've configured everything so that works locally, it will work in Atlantis.

For the next release of Atlantis this will be much more configurable. If you'd like to take a look at the RFC and add any comments you have that would be much appreciated! https://docs.google.com/document/d/13if7Bma_uTF1nhvdKx-vpU5ASakmPt-EfPSo3epv7JQ/edit?usp=sharing

@powellchristoph
Copy link
Author

Outstanding information. Thank you! I will familiarize myself more with it and definitely take a look at the RFC.

@powellchristoph
Copy link
Author

Sorry, re-opening as I require more information. Perhaps I am missing something or not using Terraform correctly.

I am attempting to use projects as our environments, ie staging, production, etc and have a shared modules directory that each environment references. I want the envs to be completely segregated so that a change in one env cannot be inadvertently pushed to another. I also want separate state files for each env.

In my testing, it appears that Atlantis runs Terraform in every directory. So a PR containing a change in multiple envs will cause Atantis to run them all and a change in a module will cause Atlantis to run it in the repo root ./.

Can I accomplish what I want with Atlantis or am I not using the tool correctly?

Thank you for the information.

@powellchristoph
Copy link
Author

I think I can accomplish this by not using workspaces (this created new state files) and being disciplined with PRs. But this doesn't solve the modules issue.

@lkysow
Copy link
Member

lkysow commented Feb 20, 2018

Hi Chris,
Right now there are some problems with Atlantis that you've identified. I'm going to try and fix them as soon as I can. Hopefully I can get a release out for you tonight.

Here's the issues:

  1. If there's a change in a modules/ directory we run plan at the root. I'm going to fix this such that it detects there's no main.tf in the root and so doesn't run plan in the root. You'll still have the problem where if you only change something in modules/ atlantis won't know where to run plan. You'll either have to make a whitespace change in your staging/production dirs or wait for a fix I'm pushing to allow for an atlantis plan -d <directory> command. When 0.3 comes out you'll be able to use atlantis.yaml to accomplish this.

  2. Atlantis will run plan in staging/ and production/ if changes have been made in those directories. That's not a problem on its own. What is a problem is that you only have access to atlantis apply which will run the apply for both staging and production at the same time :(. To fix this you can either use multiple PR's like you mentioned or wait for my fix to allow for the atlantis apply -d <directory> command

lkysow added a commit that referenced this issue Feb 20, 2018
Fixes #12. Previously we would assume that if there was a change
in any modules/ directory, we should run plan in the parent. Now
we first check whether the parent has a main.tf file. If it doesn't
then we assume it's not actually the root of a project.
@powellchristoph
Copy link
Author

Thank you very much for the quick response!

@lkysow
Copy link
Member

lkysow commented Feb 22, 2018 via email

@lkysow
Copy link
Member

lkysow commented Feb 26, 2018

The ability to run plan/apply with -d directory is on master now. I want to merge another change that comments back on the PR if you use the wrong flags before I cut a new release but if you want to run master now you should be good to go with your directory structure!

You can use
atlantis plan -d staging
and
atlantis apply -d staging

meringu pushed a commit to meringu/atlantis that referenced this issue May 29, 2023
Repo owner, name => repoFullName
PullID => PullNum to match GitHub API
PR => Pull to match GitHub API and avoid writing PRID anywhere
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