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

fix: atlantis import on workspaces #2937

Merged
merged 3 commits into from
Jan 11, 2023

Conversation

krrrr38
Copy link
Contributor

@krrrr38 krrrr38 commented Jan 5, 2023

what

why

atlantis import require terraform init process for initialize dir. At that time terraform workspace select is also required like plan_step_runner.

Asis impl doesn't switch workspace, so not work atlantis import on workspace.

tests

  • add workspace_step_runner_delegate_test.go as unit testing
  • add import_step_runner workspace switch unit test
  • add e2e import-workspace test

references

@krrrr38 krrrr38 force-pushed the fix-import-workspace branch from 68c2348 to 5b48836 Compare January 5, 2023 22:55
@krrrr38 krrrr38 force-pushed the fix-import-workspace branch from 5b48836 to 7d12f31 Compare January 5, 2023 22:56
@krrrr38 krrrr38 marked this pull request as ready for review January 5, 2023 22:58
@krrrr38 krrrr38 requested a review from a team as a code owner January 5, 2023 22:58
@@ -100,59 +104,7 @@ func (p *PlanStepRunner) remotePlan(ctx command.ProjectContext, extraArgs []stri
return p.fmtPlanOutput(output, tfVersion), nil
}

// switchWorkspace changes the terraform workspace if necessary and will create
// it if it doesn't exist. It handles differences between versions.
func (p *PlanStepRunner) switchWorkspace(ctx command.ProjectContext, path string, tfVersion *version.Version, envs map[string]string) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is moved into workspace_step_runner_delegate.go (_delegate.go is used like minimum_version_step_runner_delegate.go)

@@ -24,358 +25,12 @@ import (
. "github.com/runatlantis/atlantis/testing"
)

func TestRun_NoWorkspaceIn08(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests are test for workspace, so moved into workspace_step_runner_delegate_test.go

@@ -57,6 +59,22 @@ type Runner interface {
Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error)
}

// NullRunner is a runner that isn't configured for a given plan type but outputs nothing
type NullRunner struct{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moved

. "github.com/runatlantis/atlantis/testing"
)

func TestRun_NoWorkspaceIn08(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moved from plan_step_runner_test.go

terraformExecutor: terraformExecutor,
defaultTFVersion: defaultTfVersion,
}
return NewWorkspaceStepRunnerDelegate(terraformExecutor, defaultTfVersion, runner)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this delegation is the most important fix in this PR.

@nitrocode nitrocode changed the title fix: atlantis import not work on workspace fix: atlantis import on workspaces Jan 7, 2023
@nitrocode nitrocode added this to the 0.22.3 milestone Jan 7, 2023
Copy link
Member

@nitrocode nitrocode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @krrrr38 !

Let's get some more eyes on this before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

atlantis import does not set terraform.workspace
3 participants