-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: atlantis import on workspaces #2937
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
Merged
+769
−547
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
server/controllers/events/testfixtures/test-repos/import-workspace/atlantis.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: 3 | ||
projects: | ||
- name: dir1-ops | ||
dir: dir1 | ||
workspace: ops |
17 changes: 17 additions & 0 deletions
17
server/controllers/events/testfixtures/test-repos/import-workspace/dir1/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
resource "random_id" "dummy1" { | ||
count = terraform.workspace == "ops" ? 1 : 0 | ||
|
||
keepers = {} | ||
byte_length = 1 | ||
} | ||
|
||
resource "random_id" "dummy2" { | ||
count = terraform.workspace == "ops" ? 1 : 0 | ||
|
||
keepers = {} | ||
byte_length = 1 | ||
} | ||
|
||
output "workspace" { | ||
value = terraform.workspace | ||
} |
20 changes: 20 additions & 0 deletions
20
...ers/events/testfixtures/test-repos/import-workspace/exp-output-import-dir1-ops-dummy1.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Ran Import for project: `dir1-ops` dir: `dir1` workspace: `ops` | ||
|
||
```diff | ||
random_id.dummy1[0]: Importing from ID "AA"... | ||
random_id.dummy1[0]: Import prepared! | ||
Prepared random_id for import | ||
random_id.dummy1[0]: 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: | ||
* `atlantis plan -p dir1-ops` | ||
|
||
|
20 changes: 20 additions & 0 deletions
20
...ers/events/testfixtures/test-repos/import-workspace/exp-output-import-dir1-ops-dummy2.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Ran Import for project: `dir1-ops` dir: `dir1` workspace: `ops` | ||
|
||
```diff | ||
random_id.dummy2[0]: Importing from ID "BB"... | ||
random_id.dummy2[0]: Import prepared! | ||
Prepared random_id for import | ||
random_id.dummy2[0]: 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: | ||
* `atlantis plan -p dir1-ops` | ||
|
||
|
3 changes: 3 additions & 0 deletions
3
server/controllers/events/testfixtures/test-repos/import-workspace/exp-output-merge.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Locks and plans deleted for the projects and workspaces modified in this pull request: | ||
|
||
- dir: `dir1` workspace: `ops` |
22 changes: 22 additions & 0 deletions
22
server/controllers/events/testfixtures/test-repos/import-workspace/exp-output-plan.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Ran Plan for project: `dir1-ops` dir: `dir1` workspace: `ops` | ||
|
||
```diff | ||
|
||
No changes. Your infrastructure matches the configuration. | ||
|
||
Terraform has compared your real infrastructure against your configuration | ||
and found no differences, so no changes are needed. | ||
|
||
``` | ||
|
||
* :arrow_forward: To **apply** this plan, comment: | ||
* `atlantis apply -p dir1-ops` | ||
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url) | ||
* :repeat: To **plan** this project again, comment: | ||
* `atlantis plan -p dir1-ops` | ||
|
||
--- | ||
* :fast_forward: To **apply** all unapplied plans from this pull request, comment: | ||
* `atlantis apply` | ||
* :put_litter_in_its_place: To delete all plans and locks for the PR, comment: | ||
* `atlantis unlock` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,21 +8,29 @@ import ( | |
"github.com/runatlantis/atlantis/server/events/command" | ||
) | ||
|
||
type ImportStepRunner struct { | ||
TerraformExecutor TerraformExec | ||
DefaultTFVersion *version.Version | ||
type importStepRunner struct { | ||
terraformExecutor TerraformExec | ||
defaultTFVersion *version.Version | ||
} | ||
|
||
func (p *ImportStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { | ||
tfVersion := p.DefaultTFVersion | ||
func NewImportStepRunner(terraformExecutor TerraformExec, defaultTfVersion *version.Version) Runner { | ||
runner := &importStepRunner{ | ||
terraformExecutor: terraformExecutor, | ||
defaultTFVersion: defaultTfVersion, | ||
} | ||
return NewWorkspaceStepRunnerDelegate(terraformExecutor, defaultTfVersion, runner) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this delegation is the most important fix in this PR. |
||
} | ||
|
||
func (p *importStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { | ||
tfVersion := p.defaultTFVersion | ||
if ctx.TerraformVersion != nil { | ||
tfVersion = ctx.TerraformVersion | ||
} | ||
|
||
importCmd := []string{"import"} | ||
importCmd = append(importCmd, extraArgs...) | ||
importCmd = append(importCmd, ctx.EscapedCommentArgs...) | ||
out, err := p.TerraformExecutor.RunCommandWithVersion(ctx, filepath.Clean(path), importCmd, envs, tfVersion, ctx.Workspace) | ||
out, err := p.terraformExecutor.RunCommandWithVersion(ctx, filepath.Clean(path), importCmd, envs, tfVersion, ctx.Workspace) | ||
|
||
// If the import was successful and a plan file exists, delete the plan. | ||
planPath := filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectName)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
server/core/runtime/mocks/matchers/recv_chan_of_models_line.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.