Commit Graph

77 Commits

Author SHA1 Message Date
myoung34
a6e5c16608 Feature: Add HEAD_COMMIT env var (#1392) 2021-02-22 21:47:00 -08:00
Nish Krishnan
8598c37671 Support pre-workflow hooks on all comment/auto triggered commands. (#43) (#1418)
Fixes pre-workflow-hooks not logging errors #1371
Prevents pre-workflow-hook from locking and cloning the dir if there are no hooks registered. #1342
2021-02-22 08:34:26 -08:00
Sarvar Muminov
af2a806870 Implement a new policy check workflow (#1317)
* Adding policy_check support into yaml config

* Added policy check model and runtime structs

* Adding BuildPolicyCheckCommand to ProjectCommandBuilder

* Return incorrectly deleted code

* Remove BuildAutoPolicyPlanCommand from ProjectCommandBuilder

* Split runAutoCommand into two functions

runAutoPlanCommand - does what originally RunAutoplancommand was doing
except now it returns CommandResult and []models.ProjectCommandContext
runAutoPolicyCheckCommand - accepts CommandContext, CommandResult, and
[]models.ProjectCommandContext as arguments and runs PolicyCheckStep runner

* Refactor RunCommentCommand
* Remove BuildPolicyCheckCommand and rename StepCmdExec back to TerraformExec
* Add policy step runner logic and conftest interfaces.
* Add show step runner to policy check stage.

* Adding models.PolicyCheckCommand to buildCtx

This also means buildPlanAllCommands call buildCtx twice once with
models.PlanCommand and once with models.PolicyCheckCommand

* Adding new project_command_builder that supports policy_check

* Refactoring PolicyCheck specific logic into a PolicyCheckProjectCommandBuilder

* Moving events.CommandContext to models.CommandContext this will allow me
to remove buildCtx method and move ProjectCommandContext creation into
models package

* Policy Owners might be different types, for that reason we are
refactoring Owners into its own struct with specific keys defining
different owner types

Co-authored-by: Nish Krishnan <nishk@lyft.com>
Co-authored-by: Nish Krishnan <nishkrishnan@users.noreply.github.com>
2021-02-10 18:13:44 -08:00
Sarvar Muminov
3456dc934b Add pre workflow custom hooks to run scripts before workflow execution(plan, apply, etc) (#1255)
* Updated runatlantis.io/docs to have `pre-workflow-hooks` use cases and examples
2020-12-14 15:19:52 -05:00
Alex Castle
8d921a7dc7 Fix >= 0.12.0 version detection for versions with prereleases 2020-12-03 23:20:44 -05:00
Kate Nelson
fa4b703f9a Log apply start at info level 2020-07-23 10:35:38 -04:00
Richard Lee
0f496c867a Export ctx.RepoRelDir to run step environment. (#1063)
* Export ctx.RepoRelDir to run step environment.
2020-06-01 17:06:56 -07:00
Luke Kysow
8979a5fd09 Update pegomock 2020-05-25 11:58:50 -07:00
Luke Kysow
82afe0b061 Fix lint issues 2020-04-13 10:04:37 -07:00
Tim Birkett
d6cfe5b20e Add status-name command line arg, config and tests 2020-01-20 10:11:21 -06:00
Luke Kysow
e56f14a781 Log output of failed terraform workspace new cmd 2019-10-25 18:15:50 -07:00
Luke Kysow
c646f20c34 Actually pass env vars between steps
Also some refactoring and testing.
2019-08-21 15:12:35 +02:00
Andrii Nasinnyk
33c0a72add Add var step to workflows
Add new var step for setting environment variable in workflows.
2019-08-21 15:06:49 +02:00
Maxime Deravet
d6f2579cf9 Ensure terraform_version is downloaded when using non built-in step. Fixes #675 2019-08-01 14:32:32 -07:00
Maxime Deravet
8180f35a1a Append terraform binary dir to PATH when running custom commands (#678)
Append Atlantis terraform binary dir to PATH when running custom commands
2019-07-16 15:00:10 +01:00
Luke Kysow
b7d4e998f6 Detect remote ops for TF >= 0.12.0 (#705)
The error message we use to detect remote ops changed between 0.11.14
and 0.12.0. Recognize this new error message.
2019-07-12 11:14:52 +01:00
Luke Kysow
9a21eef7a0 Escape additional comment args. (#699)
Remove extra quoting and instead add a backslach to each character in
the extra args before appending it to the command.
ex. atlantis plan -- -var key=val will result in:
  sh -c "atlantis plan \-\v\a\r \k\e\y\=\v\a\l"
Fixes #697.
2019-07-11 17:42:32 +01:00
Alex Rowley
dd02deaf76 Add CommentArgs to run step runner (#693)
Add CommentArgs to run step runner

This should allow the extra args passed in the comment to be used by
run steps

Fixes #670
2019-07-11 14:21:36 +01:00
Luke Kysow
915e15f30e Upgrade pegomock to 2.5 2019-06-14 14:39:26 +01:00
Luke Kysow
e45bc33330 Don't include errored cmd output twice.
Since we're including the command output inside the error, we don't need
to also return the output. This was resulting in the error output being
printed twice.
2019-05-07 09:22:25 -04:00
Luke Kysow
cf490f86f0 Refactor run_step_runner test cases 2019-04-08 11:19:25 -03:00
Niko Virtala
83c81db7de tests with or without project name declaration. 2019-04-07 13:33:58 +03:00
Niko Virtala
6ee1cf6ce4 expose project name environment variable. 2019-04-06 21:18:16 +03:00
Luke Kysow
609bf84b9a Fix apply all with project name bug
Previously, if you were using project names and you had two projects
with the same directory and workspace but different workflows, running
"atlantis apply" would fail. This was because we weren't figuring out
what the project name was for each pending plan.

This change fixes this by extracting the project name from the planfile.
We also handle /'s in the project name by substituting them with '::'.
This allows us to convert them back to /'s when we're figuring out the
project names from the filenames. It's safe to do this because : isn't
an allowed character for project names.

We also remove a final substitution of invalid filename characters
because we rely on the validation of the project names instead which
happens when validating the atlantis.yaml file.
2019-04-02 15:44:01 -03:00
Luke Kysow
8982a67b78 Run latest goimports 2019-03-30 20:22:49 -05:00
Luke Kysow
25fed35728 New version 3 of atlantis.yaml
This version changes how we parse custom run steps.
Previously we used the go-shlex library to parse the steps but this
caused users issues because they'd have to use weird escaping.

Now we simply pass the step directy to sh -c without any parsing. The
parsing was unnecessary.
2019-03-28 13:45:12 -05:00
Luke Kysow
d78b106cab Refactor @jjulien's server-side config work. 2019-03-27 14:47:48 -05:00
Luke Kysow
08e272854c Upgrade pegomock 2019-03-13 17:52:27 -05:00
Luke Kysow
899c77f19c Fix async tests. 2019-02-28 16:52:26 -05:00
Luke Kysow
6721eea4f1 Skip broken tests for now. 2019-02-28 15:23:08 -05:00
Luke Kysow
9e497f495e Merge pull request #503 from runatlantis/tfe-apply-check
Add better support for remote plan/apply
2019-02-28 13:05:28 -05:00
Luke Kysow
8cef308709 Add test for large outputs. 2019-02-28 12:26:46 -05:00
Luke Kysow
7f5a0fcd10 Fix test race conditions. 2019-02-28 11:49:48 -05:00
Luke Kysow
b10cf1faa7 Test remote plan/apply. 2019-02-28 11:00:56 -05:00
Luke Kysow
db1203bf0f Add better support for remote plan/apply.
Features:
- remote plans and applies will set a commit status with a link to the
Terraform Enterpise UI where the streaming output can be viewed.
- because remote plans don't support the -out flag, we diff the plan
output between plan and apply phases to ensure users are applying the
plan they expected

How:
We add a new capability to execute a terraform command while
concurrently reading its real-time output and performing actions
accordingly.
2019-02-27 17:26:00 -05:00
Andrew Urwin
20060e1de1 update test to include -upgrade 2019-02-26 16:03:59 +00:00
Andrew Urwin
aec79b95e1 adding -upgrade to init cmd 2019-02-26 15:53:54 +00:00
Luke Kysow
5e9464b820 Merge pull request #488 from runatlantis/tfe-remote-ops
Detect if using TFE remote plan/apply backend
2019-02-25 11:12:58 -05:00
Kip McEntire
901a9f6a44 Add user_name environment variable
Add USER_NAME environment variable to the documenation
2019-02-22 16:50:36 +00:00
Luke Kysow
f030fdd609 Detect if using TFE remote plan/apply backend
If so, don't run plan with -out because this isn't currently supported.
Instead, write a planfile afterwards with the text contents of the plan.

During apply, detect that the planfile was generated using a remote plan
and run apply with -auto-approve and without the planfile arg which
isn't supported.
2019-02-21 12:10:46 -05:00
Pratik Mallya
09782c4b6d Allow "Mergeable" apply requirement to work
Get the Mergeable status of the PR before updating the
Status. This allows for the Status to be a required
Status for merging the PR. This allows us to use the
atlantis status as a Required status, which is the
configuration often used, since most deployments
want to ensure tf plans have all been successfully
applied before merging

Issue: https://github.com/runatlantis/atlantis/issues/453
2019-02-09 03:26:26 -08:00
Luke Kysow
d2abdb569a Provide base branch name in pull request model
This is needed in order to support the ability to check out the repo as
it would appear after the pull request is merged into the base branch.
2019-01-15 13:45:35 -05:00
Luke Kysow
e0dcb5ab13 Don't add extra -var flags when using TF >= 0.12
In Terraform 0.12 and above, you aren't allowed to set -var foo=bar
flags unless the foo variable is actually defined in code. Previously,
we were setting the following variables:
- atlantis_user
- atlantis_repo
- atlantis_repo_owner
- atlantis_repo_name
- atlantis_pull_num

Users could then use these variables if they wanted to, in their code.
The main use case was to name the assume role session in AWS:

provider "aws" {
  assume_role {
    role_arn     = "arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME"
    session_name = "${var.atlantis_user}-${var.atlantis_repo_owner}-${var.atlantis_repo_name}-${var.atlantis_pull_num}"
  }
}

This is longer possible in 0.12.
2019-01-10 15:16:21 -05:00
Luke Kysow
58493f3402 Warn if using -target flag with apply.
-target doesn't work with terraform apply when the apply is being run on
a planfile (which is how Atlantis runs plan). We should give the user an
error if they attempt this.

Fixes #399
2018-12-19 14:25:46 -06:00
Brenden Matthews
e001353ae9 Add mergeable requirement.
Introduce new `mergeable` requirement, in similar vein to the `approved`
requirement. Ran `make go-generate` to update mocks accordingly.

This addresses issue #43.
2018-12-11 16:00:04 -05:00
Luke Kysow
d211036137 Regen mocks and remove unused 2018-12-11 08:31:59 -06:00
Luke Kysow
5f89527049 Return plan output on error.
If terraform plan returns an error, we still want to print the output to
the pull request.
2018-12-07 10:15:42 -06:00
Luke Kysow
70d194830a Fix pre plan output being removed.
Prior to this change, we were formatting the output from terraform plan
inside the markdown_renderer. Part of this formatting is to remove all
output relating to refreshing state. The way we were doing this was to
simply delete all lines before the refreshing completes.

The problem with this approach was that any output from custom steps
that ran before plan would also be deleted. This change moves the
formatting of the plan output inside the plan step. Then the
markdown_renderer deals with the pre-formatted output and doesn't need
to delete anything before it combines all the step outputs into one.
2018-11-30 08:54:20 -06:00
Luke Kysow
2d214b2727 Restrict possible project names.
We should only allow project names (which are specified in an
atlantis.yaml file) that don't need to be url escaped. The one
exceptional character is '/' which we allow because users like to name
their projects to match the directory they're in. We use the same rule
that Terraform uses for workspace names.

I've also changed the characters that are replaced when writing out the
plan filename to only remove invalid filename characters instead of just
allowing alphanumeric. This is the smallest amount of change required to
ensure the filename is valid.
2018-10-30 13:01:48 -05:00
John Lin
b652568798 replace all invalid char in plan filename 2018-10-30 11:43:24 -05:00