Commit Graph

354 Commits

Author SHA1 Message Date
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
Luke Kysow
bebbcb8a4d Fix automerge bug in Bitbucket Server
BB Server requires we send a 'version' parameter along with our call to
/merge.
2019-02-19 17:30:28 -05:00
Pierre Hanselmann
dd6c3241b9 Set specific check on diagnostics:ping bitbucket event 2019-02-15 13:58:32 +01:00
Luke Kysow
f4e1472aef Merge pull request #469 from runatlantis/mergeability
Get mergeable status *before* changing build status
2019-02-11 14:49:40 -06:00
Luke Kysow
4e429581b0 Refactor changes to get mergeability early 2019-02-11 14:46:18 -06:00
Luke Kysow
81693d79b3 Add header to disable bitbucket xsrf
Fixes #465 which is caused by XSRF detection on Bitbucket server and
cloud.
2019-02-11 11:38:44 -06:00
Luke Kysow
45a6823eb2 Merge pull request #466 from runatlantis/gh-automerge
GitHub Automerge Types
2019-02-11 11:22:49 -06:00
Luke Kysow
def41f6cef Add tests for GH merge-type detection. 2019-02-11 11:12:15 -06:00
Luke Kysow
44f0094b75 Fix issues with terraform execution.
Previously I wrote a bunch of code to deal with terraform panicking.
This code used a pipe as the stdout/err buffer and there was a bug
because I wasn't reading off the pipe and it would get full.

While testing a fix, I realized when Terraform panics, the previous code
using CombinedOutput() just worked. As a result, I'm switching back to
that code.
2019-02-11 10:20:55 -06: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
Brenden Matthews
862b5228d0 [automerge] Use available merge methods.
For repos with certain merge methods disabled (such as 'merge'), simply
hitting the GitHub `/merge` endpoint is not sufficient. Instead, we need
to check which methods are actually available, then use the appropriate
method.

With this change it will:

 1. Default to 'merge' if enabled
 2. Use 'rebase' if 'merge' is disabled and rebase is enabled
 3. Use 'squash' if 'merge' is disabled
2019-02-07 16:18:28 -05:00
Luke Kysow
74e9bbb82b Add automerge feature.
Automerging merges pull requests automatically if all plans have been
successfully applied.

* Save status of PR's to BoltDB so after each apply, we can check if
there are pending plans.
* Add new feature where we delete successful plans *unless* all plans
have succeeded *if* automerge is enabled. This was requested by users
because when automerge is enabled, they want to enforce that a pull
request's changes have been fully applied. They asked that plans not be
allowed to be applied "piecemeal" and instead, all plans must be
generated successfully prior to allowing any plans to be applied.
2019-02-06 16:27:43 -06:00
Luke Kysow
70235d8e8f Update to latest linters. Fix errors. 2019-01-22 13:29:42 -05:00
Luke Kysow
a9d5feac84 Merge pull request #427 from runatlantis/checkout-strategy
Add new --checkout-strategy flag
2019-01-17 10:09:51 -05:00
Luke Kysow
16a4946bea Test new checkout logic. 2019-01-16 18:32:02 -05:00
Luke Kysow
054d3bc5f6 Fix skipped test 2019-01-16 12:13:37 -05:00
Luke Kysow
501db6b66e Fix gometalinter errors
Also disable test linters since we already run tests.
2019-01-15 15:45:01 -05:00
Luke Kysow
8b77b95a16 Add checkout-strategy flag.
This flag can be set to either branch (default) or merge. If set to
branch, we will check out the head branch of the pull request (the
source). If set to merge, we will check out the base branch of the pull
request (the destination) and then attempt to perform a git merge of the
pull request branch. This simulates what will happen if the pull request
is merged.

This allows us to perform terraform commands on what the state of the
repo will be *after* the pull request is merged. This is useful if users
are often opening up pull requests from branches that aren't up to date
with master. With the branch strategy, the terraform plan might be
deleting resources that have been created in the master branch but with
the merge strategy, we merge the branch's changes into the master branch
and so don't have this problem.
2019-01-15 15:45:01 -05: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
1d7bb42955 Fix tests 2019-01-10 19:46:29 -05:00
Luke Kysow
b1e32643f5 Fix bug where Atlantis hangs on terraform crash.
Because of some weirdness with how terraform executes (it forks itself
and assigns the parent's stderr and stdout file descriptors to the
child) when terraform panics, Go's exec.CombinedOutput() blocks
indefinitely even though the terraform process has exited.

To handle this, we switch to using os.Pipe for the cmd's stderr/out
which for some reason allows Go to know when the process has exited.
Unfortunately, this brings up a new problem when reading the output from
that pipe. For some reason, after a terraform crash, we never get an EOF
on the pipe and so as we again get in a situation where we're blocking
indefinitely. To handle this, I've added an edge case where we look at
the log lines and if its the end of a terraform panic, we break out of
the loop.

Thanks Terraform 0.12-alpha for discovering this bug!
2019-01-10 17:42:30 -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
fb86e89df0 Add new --tfe-token flag for TFE backend.
The new flag takes in a Terraform Enterprise API token and attempts to
write a config file for that token to ~/.terraformrc on startup.
If the file already exists and its contents would change as a result of
us writing it, we error out.
This flag is useful if you're using the TFE backend for any of your
projects as that requires a .terraformrc file with a token for
authentication.
2019-01-09 15:11:01 -05:00
Luke Kysow
7caa043fe6 Organize fields alphabetically 2019-01-09 14:49:56 -05:00
Luke Kysow
3d8138d3fa Include moved files in GetModifiedFiles
Implement the change from the previous commit for GitLab and Bitbucket
Server/Cloud. Test the change for GitHub.

If a file is moved, we want to run plan in the directory it is moved to
*and* the directory it was moved from.
2019-01-07 16:36:09 -05:00
Kent Bredeson
aaf075b281 Add old path of moved file to list of modified files 2019-01-07 14:12:28 -06:00
Luke Kysow
3bb7c8d52f Fix version detection so it works with tf 0.12alph 2019-01-04 09:26:06 -05:00
Luke Kysow
4c665b75c4 Merge pull request #403 from runatlantis/warn-target
Warn if using -target flag with apply.
2018-12-19 14:32:08 -06:00
Luke Kysow
a6ca764e87 Merge pull request #402 from runatlantis/logging-tweaks
Tweak logging. Add timezone, use everywhere.
2018-12-19 14:26:55 -06:00
Luke Kysow
d6917e49dc Merge pull request #396 from runatlantis/workspace-configured
If dir has workspaces configured only allow those
2018-12-19 14:26:35 -06: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
Luke Kysow
c4f89958d3 Tweak logging. Add timezone, use everywhere.
- Use logger for all warnings. Previously we were writing warnings from
cmd/server.go directly to stderr which bypassed our normal log format.
- Add the timezone to log output. This is just really nice to have if
you're looking at old logs.
- Change levels to all be 4 characters: DBUG, INFO, WARN, EROR. This
makes the logs easier to read because it lines up.
- Log when we first receive the request as well as when we send a
response. This makes it easier to see where the request starts and ends.
2018-12-19 13:40:13 -06:00
Luke Kysow
68ac049ad6 Write error comment on early failures.
Previously, we were just logging when an error happened early in our
comment processing code. However it's possible for us to write comments
on error even at this early stage which will make for a better user
experience.

Fixes #398
2018-12-19 13:26:27 -06:00
Luke Kysow
a018bda4ab If dir has workspaces configured only allow those
If users have created an atlantis.yaml config for a specific directory,
only allow commands for workspaces that have been configured in that
directory. This will help prevent errors when users mis-type a workspace
name.
2018-12-18 07:25:33 -06:00
Luke Kysow
985c30c097 Don't parse gitlab comment events when on commit
Detect if the GitLab event is a comment on a commit instead of a merge
request and log a debug message that we don't support this.

Previously, Atlantis would panic if it received this event.
2018-12-14 12:04:19 -06:00
Luke Kysow
b6d821326d Update docs about mergeability 2018-12-12 14:26:46 -06:00
Luke Kysow
40d427c898 Check GitLab required approvers for mergeability 2018-12-12 12:41:33 -06:00
Luke Kysow
3c1e1ab6e3 Update gitlab lib. Fix breakages. 2018-12-12 12:41:33 -06:00
Luke Kysow
e93384fdb0 Use mergeable_state to determine if mergeable
- Need to use the mergeable_state field in GitHub to know if a pull
request is mergeable.
- Add tests.
- Since we updated our vendored go-github library, fix how we were
creating webhooks in testdrive.
2018-12-12 11:17:09 -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
10bbe0abe3 Merge pull request #378 from jocelynthode/fix_regression_gitlab
Fix URL parsing not working when passing only a domain to GitlabHostname
2018-12-10 08:39:51 -06:00
Jocelyn Thode
2adaf4b24c Fix URL parsing not working when passing only a domain to GitlabHostname
Fixes https://github.com/runatlantis/atlantis/issues/377
2018-12-08 20:27:57 +01: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
934b51b64f Add project name to comments.
If projects are configured using an atlantis.yaml with a specific
project name, include that in the output for comments. This is useful
because often the project names are better identifiers than the
directory and workspace names and also because some projects use the
same dir and workspace so the only way to differentiate them is via
their names.

Fixes #353
2018-12-04 12:01:05 -06:00
Luke Kysow
9adb7eb89a Merge pull request #372 from runatlantis/bitbucket-comment-length
Split Bitbucket Server comments if over max length
2018-12-04 10:07:55 -06:00
Luke Kysow
b13a85b4f1 Use Bitbucket 2.0 API for comments.
Bitbucket released the 2.0 version for the commenting on pull requests
API:
https://community.atlassian.com/t5/Bitbucket-questions/Re-Bitbucket-Cloud-REST-API-v2-0-Commenting-on-Pull-Re/qaq-p/849427/comment-id/30070#M30070.
Previously, this was only available in version 1.0. Since 1.0 will be
deprecated, it's best to move to the latest version.
2018-12-04 09:58:52 -06:00