Commit Graph

62 Commits

Author SHA1 Message Date
Aayush Gupta
004074a29f feat: streaming terraform logs in real-time (#1937) 2021-12-30 09:52:52 -05:00
Nish Krishnan
d914eafd2a Move core workflow packages under core. (#1684)
* Move core workflow packages under core.

* lint.
2021-07-01 12:54:44 -07:00
Gábor Lipták
a4f0e3a467 Bump golangci to 1.39.0 (#1541)
Signed-off-by: Gábor Lipták <gliptak@gmail.com>
2021-05-26 21:00:20 -04:00
Luke Kysow
a597bbbb5a Regen mocks with latest pegomock and update scripts (#1524)
* Update go-generate to run as a script

It was taking forever to run via the previous Makefile command. I don't
exactly know why. Perhaps because it was passing all the packages in as
multiple arguments?

Either way, this change allows it to actually run through in about 20
minutes.

* Regenerate all mocks using latest pegomock

Pegomock version v2.9.0

* Format mocks outside of regular mocks directory.

These mocks are outside of the regular directory due to an import cycle
causing us to have to have these not under a /mocks directory so they
need to be formatted since they're not excluded.

* Add back make test target
2021-04-23 09:26:35 -07:00
Sarvar Muminov
f0201e9eb7 Upgrade conftest version to 0.23 (#1516)
* Upgraded conftest to 0.23.0 and removed --all-namespaces flag (#62)

* Upgraded conftest to 0.23.0 and removed --all-namespaces flag

* fix tests

* fix conftest version name

* make tests pass

* Update e2e tests to use 0.23 conftest

* Fix log function

* Make test client fetch version synchronously.

* Update fixtures.

* Pinning test image

Co-authored-by: Nish Krishnan <nishk@lyft.com>
2021-04-22 20:21:17 -07:00
Nish Krishnan
7ac8106f8a Add structured logger (#54) (#1467)
This is two changes:

Replacing all usages of SimpleLogger with it's interface SimpleLogging which makes it easier to swap out loggers going forward
Nukes SimpleLogger in favor of StructuredLogger which allows us to better analyze logs in our log management system we choose.
2021-04-06 12:02:25 -07: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
Mihai Plasoianu
2c4e0c3409 Set TF_WORKSPACE env var (#1363) 2021-01-28 11:56:08 -08:00
Luke Kysow
7b2a0efc82 Merge pull request #1048 from runatlantis/update-pegomock
Update pegomock
2020-05-25 16:55:45 -07:00
Luke Kysow
8979a5fd09 Update pegomock 2020-05-25 11:58:50 -07:00
Marc Barlo
bebfdcaeef Add back the parallel_plan repo cfg option
+ Default parallel plans breaks in a lot of autoplan scenarios i.e. with shared workspaces
+ Added a set of e2e tests to check parallel plans and applies
+ Also added an option to the Terraform client to turn off the plugin cache. This was breaking the e2e test suite (never seen this error in practice)
2020-05-07 22:14:04 -07:00
Josh Soref
2cf5b0a42a Spelling (#902)
Spelling fixes
2020-01-20 12:46:00 -06:00
Luke Kysow
84e41ce110 Refactor -tf-download-url flag changes.
* Fix bad ordering of args calling NewClient()
* Make error messages clearer
2020-01-20 09:19:54 -06:00
Cullen McDermott
d4362ffec3 Add --tf-download-url configuration option 2020-01-20 09:19:54 -06: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
ee8707d239 Add flag for setting Terraform Enterprise hostname (#706)
--tfe-hostname will allow for creating a .terraformrc file with a
different hostname than app.terraform.io
2019-07-12 15:19:43 +01:00
Luke Kysow
915e15f30e Upgrade pegomock to 2.5 2019-06-14 14:39:26 +01:00
Luke Kysow
4dbdde8543 Upgrade to Terraform 0.12
To be clear, Atlantis was compatible with 0.12 before this commit, but
this change makes 0.12 the default version *if* users haven't set the
--default-tf-version flag.
2019-05-23 11:42:58 -04:00
Luke Kysow
8982a67b78 Run latest goimports 2019-03-30 20:22:49 -05:00
Luke Kysow
d78b106cab Refactor @jjulien's server-side config work. 2019-03-27 14:47:48 -05:00
Luke Kysow
ca58ebd7e0 Autodownload tf versions. Add --default-tf-version.
This changeset has two features:
1. We now automatically download the version of terraform specified in
atlantis.yaml configs if we don't already have that version available
locally.

2. Add a new --default-tf-version flag that allows users to set a
default version of Terraform that we will also download if it's not on
disk.

These mean that users don't need to build custom Docker images to just
add terraform versions. It also means that upgrading the version of
terraform that is packaged with the Atlantis Docker image won't cause
issues for existing users because as long as they're running with
--default-tf-version, Atlantis will always use that version.
2019-03-14 13:51:27 -05:00
Luke Kysow
08e272854c Upgrade pegomock 2019-03-13 17:52:27 -05:00
Luke Kysow
80f6b99397 Unskip working test 2019-03-13 17:52:27 -05:00
Luke Kysow
936a5f4a16 Remove mention of TERRAFORM_WORKSPACE env var 2019-03-05 15:57:43 -05:00
Luke Kysow
899c77f19c Fix async tests. 2019-02-28 16:52:26 -05:00
Luke Kysow
ca5ca0b218 Skip all async tests (for now). 2019-02-28 15:32:31 -05:00
Luke Kysow
8cef308709 Add test for large outputs. 2019-02-28 12:26:46 -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
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
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
3bb7c8d52f Fix version detection so it works with tf 0.12alph 2019-01-04 09:26:06 -05:00
Luke Kysow
d211036137 Regen mocks and remove unused 2018-12-11 08:31:59 -06:00
Luke Kysow
e9b7001266 Add godocs. Refactor ProjectResult. Golint errors. 2018-08-30 16:47:17 -06:00
Luke Kysow
3e650dc3a0 Fix error parsing tf version when TF_LOG set 2018-08-21 08:52:25 -10:00
Luke Kysow
3b02a1fc31 Test plan/apply all. 2018-08-09 14:23:44 -10:00
Luke Kysow
85a775b94b Fix todos. Remove TF_WORKSPACE. 2018-07-02 14:39:39 +02:00
Luke Kysow
13a70c772d Add new --allow-repo-config flag. 2018-06-30 23:27:15 +02:00
Luke Kysow
f01915876d Add env vars to run step 2018-06-29 20:20:55 +02:00
Luke Kysow
71716a6461 Cleanup unused code. 2018-06-29 19:42:28 +02:00
Luke Kysow
b5e2a730de WIP Add operators and get compiled. 2018-06-15 14:03:27 +01:00
Luke Kysow
06f68b88e4 Add TF_WORKSPACE env var when execing terraform
Even though we're switching to the right workspace this is a nice
safeguard to have. I don't think it incurs additional time.
2018-06-05 17:08:56 +01:00
Luke Kysow
b507bd0712 Add plugin cache. Don't run workspace if unneeded.
- run terraform with TF_PLUGIN_CACHE_DIR set so that terraform init will
be faster.
- check which workspace we're in and don't switch unless we need to.
- run terraform with TF_IN_AUTOMATION set so the plan output doesn't
have instructions that don't make sense. Ex.
```
This plan was saved to: /tmp/atlantis/data/repos/lkysow/atlantis-example/3/default/default.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "/tmp/atlantis/data/repos/lkysow/atlantis-example/3/default/default.tfplan"
```
2018-03-20 15:05:12 -07:00
Luke Kysow
8aca81966f Add Apache 2 license and copyright.
Add Apache 2 license and Hootsuite copyright to all golang
files. Add a disclaimer that the files have been modified
hereafter by contributors to this repo in order to abide
by the Apache 2 license requirements.
2018-03-15 17:25:02 -07:00
Luke Kysow
6c159feff4 Rename to runatlantis from atlantisnorth. 2018-02-18 21:28:18 -08:00
Luke Kysow
0299d3ee12 Move to new atlantisnorth repo 2018-02-06 13:29:36 -08:00
Luke Kysow
002980e423 Use env instead of workspace in 0.9 2017-12-21 16:34:49 -08:00