Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to disable autoplan from server config #1071

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
DataDirFlag = "data-dir"
DefaultTFVersionFlag = "default-tf-version"
DisableApplyAllFlag = "disable-apply-all"
DisableAutoplanFlag = "disable-autoplan"
DisableMarkdownFoldingFlag = "disable-markdown-folding"
GHHostnameFlag = "gh-hostname"
GHTokenFlag = "gh-token"
Expand Down Expand Up @@ -254,6 +255,10 @@ var boolFlags = map[string]boolFlag{
description: "Disable \"atlantis apply\" command so a specific project/workspace/directory has to be specified for applies.",
defaultValue: false,
},
DisableAutoplanFlag: {
description: "Disable atlantis auto planning feature",
defaultValue: false,
},
ValdirGuerra marked this conversation as resolved.
Show resolved Hide resolved
AllowDraftPRs: {
description: "Enable autoplan for Github Draft Pull Requests",
defaultValue: false,
Expand Down
1 change: 1 addition & 0 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var testFlags = map[string]interface{}{
TFETokenFlag: "my-token",
VCSStatusName: "my-status",
WriteGitCredsFlag: true,
DisableAutoplanFlag: false,
}

func TestExecute_Defaults(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions runatlantis.io/docs/provider-credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It's up to you how you provide credentials for your specific provider to Atlanti
credentials. Read their docs.
* If you're running Atlantis in a cloud then many clouds have ways to give cloud API access
to applications running on them, ex:
* [AWS EC2 Roles](https://www.terraform.io/docs/providers/aws/#ec2-role)
* [AWS EC2 Roles](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) (Search for "EC2 Role")
* [GCE Instance Service Accounts](https://www.terraform.io/docs/providers/google/provider_reference.html#configuration-reference)
* Many users set environment variables, ex. `AWS_ACCESS_KEY`, where Atlantis is running.
* Others create the necessary config files, ex. `~/.aws/credentials`, where Atlantis is running.
Expand All @@ -27,16 +27,16 @@ running and run `terraform` commands like you would locally, then Atlantis will

### Multiple AWS Accounts
Atlantis supports multiple AWS accounts through the use of Terraform's
[AWS Authentication](https://www.terraform.io/docs/providers/aws/#authentication).
[AWS Authentication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) (Search for "Authentication").

If you're using the [Shared Credentials file](https://www.terraform.io/docs/providers/aws/#shared-credentials-file)
If you're using the [Shared Credentials file](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) (Search for "Shared Credentials file")
you'll need to ensure the server that Atlantis is executing on has the corresponding credentials file.

If you're using [Assume role](https://www.terraform.io/docs/providers/aws/#assume-role)
If you're using [Assume role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) (Search for "Assume role")
you'll need to ensure that the credentials file has a `default` profile that is able
to assume all required roles.

Using multiple [Environment variables](https://www.terraform.io/docs/providers/aws/#environment-variables)
Using multiple [Environment variables](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) (Search for "Environment variables")
won't work for multiple accounts since Atlantis wouldn't know which environment variables to execute
Terraform with.

Expand Down
7 changes: 7 additions & 0 deletions runatlantis.io/docs/server-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ Values are chosen in this order:
Disable \"atlantis apply\" command so a specific project/workspace/directory has to
be specified for applies.

* ### `--disable-autoplan`
```bash
atlantis server --disable-autoplan
```
Disable atlantis auto planning


* ### `--gh-hostname`
```bash
atlantis server --gh-hostname="my.github.enterprise.com"
Expand Down
4 changes: 4 additions & 0 deletions server/events/command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type DefaultCommandRunner struct {
GitlabMergeRequestGetter GitlabMergeRequestGetter
CommitStatusUpdater CommitStatusUpdater
DisableApplyAll bool
DisableAutoplan bool
EventParser EventParsing
MarkdownRenderer *MarkdownRenderer
Logger logging.SimpleLogging
Expand Down Expand Up @@ -129,6 +130,9 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo
if !c.validateCtxAndComment(ctx) {
return
}
if c.DisableAutoplan {
return
}

projectCmds, err := c.ProjectCommandBuilder.BuildAutoplanCommands(ctx)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ func TestRunCommentCommand_DisableApplyAllDisabled(t *testing.T) {
vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, modelPull.Num, "**Error:** Running `atlantis apply` without flags is disabled. You must specify which project to apply via the `-d <dir>`, `-w <workspace>` or `-p <project name>` flags.")
}

func TestRunCommentCommand_DisableDisableAutoplan(t *testing.T) {
t.Log("if \"DisableAutoplan is true\" are disabled and we are silencing return and do not comment with error")
setup(t)
ch.DisableAutoplan = true
defer func() { ch.DisableAutoplan = false }()

When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())).
ThenReturn([]models.ProjectCommandContext{
{},
{},
}, nil)

ch.RunAutoplanCommand(fixtures.GithubRepo, fixtures.GithubRepo, fixtures.Pull, fixtures.User)
projectCommandBuilder.VerifyWasCalled(Never()).BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())
}

func TestRunCommentCommand_ClosedPull(t *testing.T) {
t.Log("if a command is run on a closed pull request atlantis should" +
" comment saying that this is not allowed")
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
SilenceForkPRErrorsFlag: config.SilenceForkPRErrorsFlag,
SilenceVCSStatusNoPlans: userConfig.SilenceVCSStatusNoPlans,
DisableApplyAll: userConfig.DisableApplyAll,
DisableAutoplan: userConfig.DisableAutoplan,
ProjectCommandBuilder: &events.DefaultProjectCommandBuilder{
ParserValidator: validator,
ProjectFinder: &events.DefaultProjectFinder{},
Expand Down
1 change: 1 addition & 0 deletions server/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type UserConfig struct {
CheckoutStrategy string `mapstructure:"checkout-strategy"`
DataDir string `mapstructure:"data-dir"`
DisableApplyAll bool `mapstructure:"disable-apply-all"`
DisableAutoplan bool `mapstructure:"disable-autoplan"`
DisableMarkdownFolding bool `mapstructure:"disable-markdown-folding"`
GithubHostname string `mapstructure:"gh-hostname"`
GithubToken string `mapstructure:"gh-token"`
Expand Down