Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
krrrr38 committed Dec 27, 2022
1 parent 91f4995 commit da8a8b1
Show file tree
Hide file tree
Showing 35 changed files with 145 additions and 106 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
github.com/xanzy/go-gitlab v0.77.0
go.etcd.io/bbolt v1.3.6
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15
golang.org/x/term v0.3.0
golang.org/x/text v0.5.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 h1:5oN1Pz/eDhCpbMbLstvIPa0b/BEQo6g6nwV3pLjfM6w=
golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
6 changes: 3 additions & 3 deletions runatlantis.io/docs/using-atlantis.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ If a flag is needed to be always appended, see [Custom Workflow Use Cases](custo
---
## atlantis state rm
```bash
atlantis state [options] rm ADDRESS... -- [terraform import flags]
atlantis state [options] rm ADDRESS... -- [terraform state rm flags]
```
### Explanation
Runs `terraform state rm` that matches the directory/project/workspace.
This command discards the terraform plan result. After an import and before an apply, another `atlantis plan` must be run again.
This command discards the terraform plan result. After run state rm and before an apply, another `atlantis plan` must be run again.

### Examples
```bash
Expand All @@ -192,7 +192,7 @@ atlantis state -w staging rm ADDRESS
```

::: tip
* If import for_each resources, it requires a single quoted address.
* If run state rm to for_each resources, it requires a single quoted address.
* ex. `atlantis state rm 'aws_instance.example["foo"]'`
:::

Expand Down
10 changes: 3 additions & 7 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,10 @@ func TestGitHubWorkflow(t *testing.T) {
ModifiedFiles: []string{"dir1/main.tf", "dir2/main.tf"},
ExpAutoplan: true,
Comments: []string{
"atlantis import -d dir1 random_id.dummy1 AA",
"atlantis import -d dir2 random_id.dummy2 BB",
"atlantis import -d dir1 random_id.dummy AA",
"atlantis import -d dir2 random_id.dummy BB",
"atlantis plan",
"atlantis state rm random_id.dummy1 AA",
"atlantis state rm -d dir1 random_id.dummy1",
"atlantis state -d dir2 rm random_id.dummy2",
"atlantis state rm random_id.dummy",
"atlantis plan",
},
ExpReplies: [][]string{
Expand All @@ -508,8 +506,6 @@ func TestGitHubWorkflow(t *testing.T) {
{"exp-output-import-dummy2.txt"},
{"exp-output-plan.txt"},
{"exp-output-state-rm-multiple-projects.txt"},
{"exp-output-state-rm-dummy1.txt"},
{"exp-output-state-rm-dummy2.txt"},
{"exp-output-plan-again.txt"},
{"exp-output-merged.txt"},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "random_id" "dummy1" {
resource "random_id" "dummy" {
keepers = {}
byte_length = 1
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "random_id" "dummy2" {
resource "random_id" "dummy" {
keepers = {}
byte_length = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ plan. Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

# random_id.dummy1 will be created
+ resource "random_id" "dummy1" {
# random_id.dummy will be created
+ resource "random_id" "dummy" {
+ b64_std = (known after apply)
+ b64_url = (known after apply)
+ byte_length = 1
Expand Down Expand Up @@ -50,8 +50,8 @@ plan. Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

# random_id.dummy2 will be created
+ resource "random_id" "dummy2" {
# random_id.dummy will be created
+ resource "random_id" "dummy" {
+ b64_std = (known after apply)
+ b64_url = (known after apply)
+ byte_length = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
Ran Import for dir: `dir1` workspace: `default`

```diff
random_id.dummy1: Importing from ID "AA"...
random_id.dummy1: Import prepared!
random_id.dummy: Importing from ID "AA"...
random_id.dummy: Import prepared!
Prepared random_id for import
random_id.dummy1: Refreshing state... [id=AA]
random_id.dummy: Refreshing state... [id=AA]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
Ran Import for dir: `dir2` workspace: `default`

```diff
random_id.dummy2: Importing from ID "BB"...
random_id.dummy2: Import prepared!
random_id.dummy: Importing from ID "BB"...
random_id.dummy: Import prepared!
Prepared random_id for import
random_id.dummy2: Refreshing state... [id=BB]
random_id.dummy: Refreshing state... [id=BB]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ plan. Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

# random_id.dummy1 will be created
+ resource "random_id" "dummy1" {
# random_id.dummy will be created
+ resource "random_id" "dummy" {
+ b64_std = (known after apply)
+ b64_url = (known after apply)
+ byte_length = 1
Expand Down Expand Up @@ -50,8 +50,8 @@ plan. Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

# random_id.dummy2 will be created
+ resource "random_id" "dummy2" {
# random_id.dummy will be created
+ resource "random_id" "dummy" {
+ b64_std = (known after apply)
+ b64_url = (known after apply)
+ byte_length = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Ran Plan for 2 projects:

### 1. dir: `dir1` workspace: `default`
```diff
random_id.dummy1: Refreshing state... [id=AA]
random_id.dummy: Refreshing state... [id=AA]

No changes. Your infrastructure matches the configuration.

Expand All @@ -23,7 +23,7 @@ and found no differences, so no changes are needed.
---
### 2. dir: `dir2` workspace: `default`
```diff
random_id.dummy2: Refreshing state... [id=BB]
random_id.dummy: Refreshing state... [id=BB]

No changes. Your infrastructure matches the configuration.

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
**State Failed**: state rm cannot run on multiple projects. please specify one project.
Ran State for 2 projects:

1. dir: `dir1` workspace: `default`
1. dir: `dir2` workspace: `default`

### 1. dir: `dir1` workspace: `default`
```diff
Removed random_id.dummy
Successfully removed 1 resource instance(s).
```

* :repeat: To **plan** this project again, comment:
* `atlantis plan -d dir1`


---
### 2. dir: `dir2` workspace: `default`
```diff
Removed random_id.dummy
Successfully removed 1 resource instance(s).
```

* :repeat: To **plan** this project again, comment:
* `atlantis plan -d dir2`


---
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Ran State `rm` for dir: `.` workspace: `default`
```diff
Removed random_id.for_each["overridden"]
Successfully removed 1 resource instance(s).

```

* :repeat: To **plan** this project again, comment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Ran State `rm` for dir: `.` workspace: `default`
Removed random_id.count[0]
Removed random_id.simple
Successfully removed 2 resource instance(s).

```

* :repeat: To **plan** this project again, comment:
Expand Down
6 changes: 3 additions & 3 deletions server/core/runtime/import_step_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/hashicorp/go-version"
. "github.com/petergtz/pegomock"
"github.com/runatlantis/atlantis/server/core/runtime/mocks/matchers"
runtimematchers "github.com/runatlantis/atlantis/server/core/runtime/mocks/matchers"
"github.com/runatlantis/atlantis/server/core/terraform/mocks"
matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers"
tfmatchers "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/logging"
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestImportStepRunner_Run_Success(t *testing.T) {
DefaultTFVersion: tfVersion,
}

When(terraform.RunCommandWithVersion(matchers.AnyModelsProjectCommandContext(), AnyString(), AnyStringSlice(), matchers2.AnyMapOfStringToString(), matchers2.AnyPtrToGoVersionVersion(), AnyString())).
When(terraform.RunCommandWithVersion(runtimematchers.AnyModelsProjectCommandContext(), AnyString(), AnyStringSlice(), tfmatchers.AnyMapOfStringToString(), tfmatchers.AnyPtrToGoVersionVersion(), AnyString())).
ThenReturn("output", nil)
output, err := s.Run(context, []string{}, tmpDir, map[string]string(nil))
Ok(t, err)
Expand Down
33 changes: 33 additions & 0 deletions server/core/runtime/mocks/matchers/command_projectcontext.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions server/core/runtime/state_rm_step_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/hashicorp/go-version"
. "github.com/petergtz/pegomock"
"github.com/runatlantis/atlantis/server/core/runtime/mocks/matchers"
runtimematchers "github.com/runatlantis/atlantis/server/core/runtime/mocks/matchers"
"github.com/runatlantis/atlantis/server/core/terraform/mocks"
matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers"
tfmatchers "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/logging"
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestStateRmStepRunner_Run_Success(t *testing.T) {
DefaultTFVersion: tfVersion,
}

When(terraform.RunCommandWithVersion(matchers.AnyModelsProjectCommandContext(), AnyString(), AnyStringSlice(), matchers2.AnyMapOfStringToString(), matchers2.AnyPtrToGoVersionVersion(), AnyString())).
When(terraform.RunCommandWithVersion(runtimematchers.AnyModelsProjectCommandContext(), AnyString(), AnyStringSlice(), tfmatchers.AnyMapOfStringToString(), tfmatchers.AnyPtrToGoVersionVersion(), AnyString())).
ThenReturn("output", nil)
output, err := s.Run(context, []string{}, tmpDir, map[string]string(nil))
Ok(t, err)
Expand Down
Loading

0 comments on commit da8a8b1

Please sign in to comment.