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

The case of import to workspaces on "local" backend doesn't work without extra options #23899

Open
cazorla19 opened this issue Jan 20, 2020 · 0 comments

Comments

@cazorla19
Copy link

Terraform Version

Happens on both 0.11.x and 0.12.x.

Terraform Configuration Files

terraform {
  backend "local" {
    workspace_dir = "workspaces"
  }
}

Expected Behavior

terraform import aws_vpc.this vpc-033184ss456

This command should import the resource exactly to the workspace being selected.

Actual Behavior

This command creates the default workspace state behind workspaces/ directory and imports the desired resource to this one instead of importing to the selected workspace. One more weird thing: running this command for another resource, it's actually overwriting the previous one, having only the last one from these two at the end.

Workaround out of documentation guidelines:

terraform import -state-out=workspaces/staging/terraform.tfstate aws_vpc.this vpc-033184ss456

Steps to Reproduce

  1. terraform init should init the local backend on the workspace
  2. terraform import aws_vpc.this vpc-033184ss456 – could be any resource, this must be provider/resource independent issue.
  3. Check out the local backend to verify the resource has been imported to the default workspace instead of the selected one.
  4. Repeat the command on another resource to discover the fact that it overwrites the previous resource
  5. terraform import -state-out=workspaces/[workspace_name]/terraform.tfstate aws_vpc.this vpc-033184ss456 to ensure it has been imported to the desired workspace with the flag

Additional Context

In case if this issue is really valuable and this behavior is unexpected, I'd propose two solutions:

  1. Fix the actual problem by overriding the behavior when Terraform is being set up with workspaces
  2. Add the quick note in documentation (I could take this over for sure)

Thank you and have a great week 🥇

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

No branches or pull requests

2 participants