mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-02 16:58:32 +00:00
4.9 KiB
4.9 KiB
plan file names
- named as {owner}{repo}{pull number}
- saved to s3 at {bucket}/{prefix}/{owner}/{repo}/{owner}{repo}{pull}{_optional_relative_path}.tfplan{.optional env}, bucket=hootsuite-terraform, prefix=plans
- planfilename = ".tfplan.{env}" if at root, otherwise "_relative_plan_path.tfplan.{env}". If no env then no .{env} suffix
- the trick with the plan names is when we're running an apply, we pull out all plans that match: plans/{owner}/{repo}/{owner}{repo}{pullNum}
- now we still need to know where to run the plan from, which is why we include the path as part of the filename, ex. ...{pullNum}{relative}{path}.tfplan.{env}.
- we could figure out the plan paths from the pull request, however we would still need to know which plan file is which, hence needing to have the relative path as part of the plan
results:
- apply/plan gives either a "Terraform Apply:" or a "Terraform Plan:" prefix and the same for each path "Terraform plan for
{path}" - either a setup error/failure (basically anything pre-path fork)
- once it gets to the path phase, each path can have a success/error/failure
- so what needs a template?
- pre-path-execution setup failures/successes with a "{Command} {Statused}" prefix, ex. Apply Failed:
- path-execution results
naming:
Atlantishas (currently) threecommands:plan,apply, andhelpTerraformhascommandslikeplan,apply,get,remote- When a user comments with an
Atlantiscommand, they trigger anexecution- We determine the
Atlantiscommand(ex.planorapply)- We also determine the
contextof theexecution, orexecutionContext. This consists of data like therepo owner, thepull request number, thecommentor username, etc.
- We also determine the
- From the
commandtype, we know whichexecutorto use. Either thePlanExecutor, or theApplyExecutor - We then tell the
executortoexecutethecommand - There may be multiple
terraform projectsinvolved in anexecutionbecause we may have to runterraform plan/applyin multiplepaths. - The
executorreturns to us theexecutionResult- each
resulthas one of threestatuses:successful,failed,erroredsuccessfulis when... it was successfulfailedis when it didn't work but because of a user-solvable problem, like their terraform was wrong, or that environment doesn't existerroredis when there was an internal Atlantis error that couldn't be fixed by the user, like a request to github timed out
resulthas sub-types to represent different results. For example there is aPlanResultthat has the output ofterraform plan, and the url to discard the plan and lock
- each
- We then need to add a
commentback to thepull request, so werendertheexecutionResultusing arenderer. In this case, we need theGithubCommentRenderer- We can then add the
commentto thepull requestby using thegithubClient
- We can then add the
- We determine the
components: clients for external services: - github (created) - s3 (created) clients for on-host "services": - git - aws cli - terraform commands: - plan - apply - help
logging guidelines:
- all lowercase (first letter of each line will be autocapitalized)
- levels:
- debug is for developers of atlantis
- info is for users (expected that people run on info level)
- warn is for something that might be a problem but we're not sure
- error is for something that's definitely a problem
- don't log any output or multiple lines unless at debug level
- quote any string variables using %q in the fmt string, ex.
ctx.Log.Info("cleaning clone dir %q", dir)=>Cleaning clone directory "/tmp/atlantis/lkysow/atlantis-terraform-test/3" - if something is an error, ex. we couldn't clean up the workspace, use the words "failed to" in the log
- never use colons "
:" in a log since that's used to separate error descriptions and causes- if you need to have a break in your comment, either use
-or,ex.failed to clean directory, continuing regardlessorPOST /404 - Response code 404
- if you need to have a break in your comment, either use
Glossary
- Run: Encompasses the two steps (plan and apply) for modifying infrastructure in a specific environment
- Run Lock: When a run has started but is not yet completed, the infrastructure and environment that's being modified is "locked" against other runs being started for the same set of infrastructure and environment. We determine what infrastructure is being modified by combining the repository name, the directory in the repository at which the terraform commands need to be run, and the environment that's being modified
- Run Path: The path relative to the repository's root at which terraform commands need to be executed for this Run
- Run Key: The unique id for the set of infrastructure that is being modified in a Run. It is a combination of the repository name, run path, and environment
- Run Id: The id for this specific Run