With atlantis what is the preferred way of handling state?
We have a team of 3 here and would like to use this to centralise Terraform for us. I was of the understanding it's bad form to check in a terraform.tfstate file to repo so we have been excluding them which means we can't apply plans others have already worked on applying previously or our imported state. I was looking at Atlas that handles this for you as remote state when I spotted atlantis and assumed it would create and hold it's own state locally as local state but I can't find this anywhere? I was going to push our state files into that structure. Do we need to setup remote state provider and which is recommended with atlantis?
Many thanks in advance!
You should definitely use remote state.
Thanks @psalaberria002 I will look at this maybe a different bucket/folder per each environment we have in our repo as we template off a template environment and don't think we have updated all the resource names in each env to be unique.
I would recommend having multiple states. Per environment and service for example.
Add something like this to each folder you wanna have a state for.
terraform {
backend "gcs" {
project = "<your-project>"
bucket = "<yourbucket-for-states>"
prefix = "<your-env>/<service>"
credentials = "<path-to-credentials>"
}
required_version = "~> 0.11"
}
Hey Alister,
I would echo the suggestion to use remote state. Then when atlantis runs terraform apply, the remote state will be updated. You're correct in that you'll want a different location to store your state per environment otherwise you'd run into issues. If you're fully separating environments (i.e. separate accounts even) then a separate bucket might make sense. Otherwise just top-level folders per env should be fine like in the example above.
This isn't related to Atlantis but I'd also recommend that you make your remote state path match the paths in your repo so it's easy to know how to reference a remote state from a different directory.
cheers for the advice we are going to try to use our proget servers via a http remote and differing path! fingers crossed :) I will match the path to repo path as u suggest
Most helpful comment
Hey Alister,
I would echo the suggestion to use remote state. Then when atlantis runs
terraform apply, the remote state will be updated. You're correct in that you'll want a different location to store your state per environment otherwise you'd run into issues. If you're fully separating environments (i.e. separate accounts even) then a separate bucket might make sense. Otherwise just top-level folders per env should be fine like in the example above.This isn't related to Atlantis but I'd also recommend that you make your remote state path match the paths in your repo so it's easy to know how to reference a remote state from a different directory.