Skip to content

Commit d53c1a4

Browse files
committed
feat: atlantis import
1 parent f974fb5 commit d53c1a4

File tree

75 files changed

+2492
-740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2492
-740
lines changed

cmd/server.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -985,30 +985,31 @@ func (s *ServerCmd) securityWarnings(userConfig *server.UserConfig) {
985985
// being used. Right now this only applies to flags that have been made obsolete
986986
// due to server-side config.
987987
func (s *ServerCmd) deprecationWarnings(userConfig *server.UserConfig) error {
988-
var applyReqs []string
988+
var commandReqs []string
989989
var deprecatedFlags []string
990990
if userConfig.RequireApproval {
991991
deprecatedFlags = append(deprecatedFlags, RequireApprovalFlag)
992-
applyReqs = append(applyReqs, valid.ApprovedApplyReq)
992+
commandReqs = append(commandReqs, valid.ApprovedCommandReq)
993993
}
994994
if userConfig.RequireMergeable {
995995
deprecatedFlags = append(deprecatedFlags, RequireMergeableFlag)
996-
applyReqs = append(applyReqs, valid.MergeableApplyReq)
996+
commandReqs = append(commandReqs, valid.MergeableCommandReq)
997997
}
998998

999999
// Build up strings with what the recommended yaml and json config should
10001000
// be instead of using the deprecated flags.
10011001
yamlCfg := "---\nrepos:\n- id: /.*/"
10021002
jsonCfg := `{"repos":[{"id":"/.*/"`
1003-
if len(applyReqs) > 0 {
1004-
yamlCfg += fmt.Sprintf("\n apply_requirements: [%s]", strings.Join(applyReqs, ", "))
1005-
jsonCfg += fmt.Sprintf(`, "apply_requirements":["%s"]`, strings.Join(applyReqs, "\", \""))
1006-
1003+
if len(commandReqs) > 0 {
1004+
yamlCfg += fmt.Sprintf("\n apply_requirements: [%s]", strings.Join(commandReqs, ", "))
1005+
yamlCfg += fmt.Sprintf("\n import_requirements: [%s]", strings.Join(commandReqs, ", "))
1006+
jsonCfg += fmt.Sprintf(`, "apply_requirements":["%s"]`, strings.Join(commandReqs, "\", \""))
1007+
jsonCfg += fmt.Sprintf(`, "import_requirements":["%s"]`, strings.Join(commandReqs, "\", \""))
10071008
}
10081009
if userConfig.AllowRepoConfig {
10091010
deprecatedFlags = append(deprecatedFlags, AllowRepoConfigFlag)
1010-
yamlCfg += "\n allowed_overrides: [apply_requirements, workflow]\n allow_custom_workflows: true"
1011-
jsonCfg += `, "allowed_overrides":["apply_requirements","workflow"], "allow_custom_workflows":true`
1011+
yamlCfg += "\n allowed_overrides: [apply_requirements, import_requirements, workflow]\n allow_custom_workflows: true"
1012+
jsonCfg += `, "allowed_overrides":["apply_requirements","import_requirements","workflow"], "allow_custom_workflows":true`
10121013
}
10131014
jsonCfg += "}]}"
10141015

runatlantis.io/.vuepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
'custom-workflows',
7373
'repo-level-atlantis-yaml',
7474
'upgrading-atlantis-yaml',
75-
'apply-requirements',
75+
'command-requirements',
7676
'checkout-strategy',
7777
'terraform-versions',
7878
'terraform-cloud',

runatlantis.io/docs/apply-requirements.md renamed to runatlantis.io/docs/command-requirements.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Apply Requirements
1+
# Command Requirements
22
[[toc]]
33

44
## Intro
5-
Atlantis allows you to require certain conditions be satisfied **before** an `atlantis apply`
6-
command can be run:
5+
Atlantis allows you to require certain conditions be satisfied **before** `atlantis apply` and `atlantis import`
6+
commands can be run:
77

88
* [Approved](#approved) – requires pull requests to be approved by at least one user other than the author
99
* [Mergeable](#mergeable) – requires pull requests to be able to be merged
@@ -70,12 +70,12 @@ You can set the `mergeable` requirement by:
7070
apply_requirements: [mergeable]
7171
```
7272

73-
1. Or by allowing an `atlantis.yaml` file to specify the `apply_requirements` key in your `repos.yaml` config:
73+
1. Or by allowing an `atlantis.yaml` file to specify `apply_requirements` and `import_requirements` keys in your `repos.yaml` config:
7474
#### repos.yaml
7575
```yaml
7676
repos:
7777
- id: /.*/
78-
allowed_overrides: [apply_requirements]
78+
allowed_overrides: [apply_requirements, import_requirements]
7979
```
8080

8181
#### atlantis.yaml
@@ -84,6 +84,7 @@ You can set the `mergeable` requirement by:
8484
projects:
8585
- dir: .
8686
apply_requirements: [mergeable]
87+
import_requirements: [mergeable]
8788
```
8889

8990
#### Meaning
@@ -152,18 +153,19 @@ Applies to `merge` checkout strategy only.
152153

153154
#### Usage
154155
You can set the `undiverged` requirement by:
155-
1. Creating a `repos.yaml` file with the `apply_requirements` key:
156+
1. Creating a `repos.yaml` file with `apply_requirements` and `import_requirements` keys:
156157
```yaml
157158
repos:
158159
- id: /.*/
159160
apply_requirements: [undiverged]
161+
import_requirements: [undiverged]
160162
```
161163
1. Or by allowing an `atlantis.yaml` file to specify the `apply_requirements` key in your `repos.yaml` config:
162164
#### repos.yaml
163165
```yaml
164166
repos:
165167
- id: /.*/
166-
allowed_overrides: [apply_requirements]
168+
allowed_overrides: [apply_requirements, apply_requirements]
167169
```
168170

169171
#### atlantis.yaml
@@ -172,6 +174,7 @@ You can set the `undiverged` requirement by:
172174
projects:
173175
- dir: .
174176
apply_requirements: [undiverged]
177+
import_requirements: [undiverged]
175178
```
176179
#### Meaning
177180
The `merge` checkout strategy creates a temporary merge commit and runs the `plan` on the Atlantis local version of the PR
@@ -180,8 +183,8 @@ if there are no changes to the source branch. `undiverged` enforces that Atlanti
180183
with remote so that the state of the source during the `apply` is identical to that if you were to merge the PR at that
181184
time.
182185

183-
## Setting Apply Requirements
184-
As mentioned above, you can set apply requirements via flags, in `repos.yaml`, or in `atlantis.yaml` if `repos.yaml`
186+
## Setting Command Requirements
187+
As mentioned above, you can set command requirements via flags, in `repos.yaml`, or in `atlantis.yaml` if `repos.yaml`
185188
allows the override.
186189

187190
### Flags Override
@@ -197,27 +200,30 @@ If you only want some projects/repos to have apply requirements, then you must
197200
repos:
198201
- id: /.*/
199202
apply_requirements: [approved]
203+
import_requirements: [approved]
200204
# Regex that defaults all repos to requiring approval
201205
- id: /github.com/runatlantis/.*/
202206
# Regex to match any repo under the atlantis namespace, and not require approval
203207
# except for repos that might match later in the chain
204208
apply_requirements: []
209+
import_requirements: []
205210
- id: github.com/runatlantis/atlantis
206211
apply_requirements: [approved]
212+
import_requirements: [approved]
207213
# Exact string match of the github.com/runatlantis/atlantis repo
208214
# that sets apply_requirements to approved
209215
```
210216

211217
1. Specify which projects have which requirements via an `atlantis.yaml` file, and allowing
212-
`apply_requirements` to be set in in `atlantis.yaml` by the server side `repos.yaml`
218+
`apply_requirements` and `import_requirements` to be set in `atlantis.yaml` by the server side `repos.yaml`
213219
config.
214220

215221
For example if I have two directories, `staging` and `production`, I might use:
216222
#### repos.yaml
217223
```yaml
218224
repos:
219225
- id: /.*/
220-
allowed_overrides: [apply_requirements]
226+
allowed_overrides: [apply_requirements, import_requirements]
221227
# Allow any repo to specify apply_requirements in atlantis.yaml
222228
```
223229

@@ -226,13 +232,15 @@ If you only want some projects/repos to have apply requirements, then you must
226232
version: 3
227233
projects:
228234
- dir: staging
229-
# By default, apply_requirements is empty so this
235+
# By default, apply_requirements and import_requirements are empty so this
230236
# isn't strictly necessary.
231237
apply_requirements: []
238+
import_requirements: []
232239
- dir: production
233240
# This requirement will only apply to the
234241
# production directory.
235242
apply_requirements: [mergeable]
243+
import_requirements: [mergeable]
236244
237245
238246
### Multiple Requirements

runatlantis.io/docs/repo-level-atlantis-yaml.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ projects:
6060
autoplan:
6161
when_modified: ["*.tf", "../modules/**/*.tf"]
6262
enabled: true
63-
apply_requirements: [mergeable, approved]
63+
apply_requirements: [mergeable, approved, undiverged]
64+
import_requirements: [mergeable, approved, undiverged]
6465
workflow: myworkflow
6566
workflows:
6667
myworkflow:
@@ -215,10 +216,11 @@ projects:
215216
- dir: staging
216217
- dir: production
217218
apply_requirements: [approved]
219+
import_requirements: [approved]
218220
```
219221
:::warning
220-
`apply_requirements` is a restricted key so this repo will need to be configured
221-
to be allowed to set this key. See [Server-Side Repo Config Use Cases](server-side-repo-config.html#repos-can-set-their-own-apply-requirements).
222+
`apply_requirements` and `import_requirements` are restricted keys so this repo will need to be configured
223+
to be allowed to set this key. See [Server-Side Repo Config Use Cases](server-side-repo-config.html#repos-can-set-their-own-apply-or-import-requirements).
222224
:::
223225

224226
### Order of planning/applying
@@ -269,22 +271,24 @@ repo_locking: true
269271
autoplan:
270272
terraform_version: 0.11.0
271273
apply_requirements: ["approved"]
274+
import_requirements: ["approved"]
272275
workflow: myworkflow
273276
```
274277

275-
| Key | Type | Default | Required | Description |
276-
|----------------------------------------|-----------------------|-------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
277-
| name | string | none | maybe | Required if there is more than one project with the same `dir` and `workspace`. This project name can be used with the `-p` flag. |
278-
| branch | string | none | no | Regex matching projects by the base branch of pull request (the branch the pull request is getting merged into). Only projects that match the PR's branch will be considered. By default, all branches are matched. |
279-
| dir | string | none | **yes** | The directory of this project relative to the repo root. For example if the project was under `./project1` then use `project1`. Use `.` to indicate the repo root. |
280-
| workspace | string | `"default"` | no | The [Terraform workspace](https://www.terraform.io/docs/state/workspaces.html) for this project. Atlantis will switch to this workplace when planning/applying and will create it if it doesn't exist. |
281-
| execution_order_group | int | `0` | no | Index of execution order group. Projects will be sort by this field before planning/applying. |
282-
| delete_source_branch_on_merge | bool | `false` | no | Automatically deletes the source branch on merge. |
283-
| repo_locking | bool | `true` | no | Get a repository lock in this project when plan. |
284-
| autoplan | [Autoplan](#autoplan) | none | no | A custom autoplan configuration. If not specified, will use the autoplan config. See [Autoplanning](autoplanning.html). |
285-
| terraform_version | string | none | no | A specific Terraform version to use when running commands for this project. Must be [Semver compatible](https://semver.org/), ex. `v0.11.0`, `0.12.0-beta1`. |
286-
| apply_requirements<br />*(restricted)* | array[string] | none | no | Requirements that must be satisfied before `atlantis apply` can be run. Currently the only supported requirements are `approved`, `mergeable`, and `undiverged`. See [Apply Requirements](apply-requirements.html) for more details. |
287-
| workflow <br />*(restricted)* | string | none | no | A custom workflow. If not specified, Atlantis will use its default workflow. |
278+
| Key | Type | Default | Required | Description |
279+
|-----------------------------------------|-----------------------|-------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
280+
| name | string | none | maybe | Required if there is more than one project with the same `dir` and `workspace`. This project name can be used with the `-p` flag. |
281+
| branch | string | none | no | Regex matching projects by the base branch of pull request (the branch the pull request is getting merged into). Only projects that match the PR's branch will be considered. By default, all branches are matched. |
282+
| dir | string | none | **yes** | The directory of this project relative to the repo root. For example if the project was under `./project1` then use `project1`. Use `.` to indicate the repo root. |
283+
| workspace | string | `"default"` | no | The [Terraform workspace](https://www.terraform.io/docs/state/workspaces.html) for this project. Atlantis will switch to this workplace when planning/applying and will create it if it doesn't exist. |
284+
| execution_order_group | int | `0` | no | Index of execution order group. Projects will be sort by this field before planning/applying. |
285+
| delete_source_branch_on_merge | bool | `false` | no | Automatically deletes the source branch on merge. |
286+
| repo_locking | bool | `true` | no | Get a repository lock in this project when plan. |
287+
| autoplan | [Autoplan](#autoplan) | none | no | A custom autoplan configuration. If not specified, will use the autoplan config. See [Autoplanning](autoplanning.html). |
288+
| terraform_version | string | none | no | A specific Terraform version to use when running commands for this project. Must be [Semver compatible](https://semver.org/), ex. `v0.11.0`, `0.12.0-beta1`. |
289+
| apply_requirements<br />*(restricted)* | array[string] | none | no | Requirements that must be satisfied before `atlantis apply` can be run. Currently the only supported requirements are `approved`, `mergeable`, and `undiverged`. See [Command Requirements](command-requirements.html) for more details. |
290+
| import_requirements<br />*(restricted)* | array[string] | none | no | Requirements that must be satisfied before `atlantis import` can be run. Currently the only supported requirements are `approved`, `mergeable`, and `undiverged`. See [Command Requirements](command-requirements.html) for more details. |
291+
| workflow <br />*(restricted)* | string | none | no | A custom workflow. If not specified, Atlantis will use its default workflow. |
288292

289293
::: tip
290294
A project represents a Terraform state. Typically, there is one state per directory and workspace however it's possible to

runatlantis.io/docs/server-configuration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ and set `--autoplan-modules` to `false`.
495495

496496
### `--gh-team-allowlist`
497497
```bash
498-
atlantis server --gh-team-allowlist="myteam:plan, secteam:apply, DevOps Team:apply"
498+
atlantis server --gh-team-allowlist="myteam:plan, secteam:apply, DevOps Team:apply, DevOps Team:import"
499499
# or
500-
ATLANTIS_GH_TEAM_ALLOWLIST="myteam:plan, secteam:apply, DevOps Team:apply"
500+
ATLANTIS_GH_TEAM_ALLOWLIST="myteam:plan, secteam:apply, DevOps Team:apply, DevOps Team:import"
501501
```
502502
In versions v0.21.0 and later, the GitHub team name can be a name or a slug.
503503

@@ -779,7 +779,7 @@ and set `--autoplan-modules` to `false`.
779779
ATLANTIS_REQUIRE_APPROVAL=true
780780
```
781781
This flag is deprecated. It requires all pull requests to be approved
782-
before `atlantis apply` is allowed. See [Apply Requirements](apply-requirements.html) for more details.
782+
before `atlantis apply` is allowed. See [Command Requirements](command-requirements.html) for more details.
783783

784784
Instead of using this flag, create a server-side `--repo-config` file:
785785
```yaml
@@ -798,7 +798,7 @@ and set `--autoplan-modules` to `false`.
798798
ATLANTIS_REQUIRE_MERGEABLE=true
799799
```
800800
This flag is deprecated. It causes all pull requests to be mergeable
801-
before `atlantis apply` is allowed. See [Apply Requirements](apply-requirements.html) for more details.
801+
before `atlantis apply` is allowed. See [Command Requirements](command-requirements.html) for more details.
802802

803803
Instead of using this flag, create a server-side `--repo-config` file:
804804
```yaml

0 commit comments

Comments
 (0)