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

Import statement must not give and error when having workspace #35371

Closed
alecscodehub opened this issue Jun 21, 2024 · 4 comments
Closed

Import statement must not give and error when having workspace #35371

alecscodehub opened this issue Jun 21, 2024 · 4 comments
Labels
enhancement new new issue not yet triaged

Comments

@alecscodehub
Copy link

Terraform Version

Terraform v1.5.5
on darwin_amd64
+ provider registry.terraform.io/hashicorp/archive v2.1.0
+ provider registry.terraform.io/hashicorp/aws v4.9.0

Your version of Terraform is out of date! The latest version
is 1.8.5. You can update by downloading from https://www.terraform.io/downloads.html

Use Cases

When using

import {
  to = aws_identitystore_group_membership.example
  id = "d-0000000000/00000000-0000-0000-0000-000000000000"
}

and you import for default workspace all ok, but when you import and you have several workspace you getting a error and you dont have a way to just say apply this only for this workspace.

Attempted Solutions

The solution is to comment the code which is not "clean"
/*
import {
to = aws_identitystore_group_membership.example
id = "d-0000000000/00000000-0000-0000-0000-000000000000"
}
*/

Proposal

Allow Count inside a import.

import {
count = terraform.workspace == "dev" ? 1 : 0
to = aws_identitystore_group_membership.example
id = "d-0000000000/00000000-0000-0000-0000-000000000000"
}

References

No response

@alecscodehub alecscodehub added enhancement new new issue not yet triaged labels Jun 21, 2024
@jbardin
Copy link
Member

jbardin commented Jun 21, 2024

Hi @alecscodehub,

import blocks deliberately do not have a count meta-argument, because instances to be imported always have unique identities unrelated to the order the instances in the state. You can still use the same conditional expressions in the for_each argument, or provide the id's more dynamically via input variables.

locals {
  group_membership = terraform.workspace == "dev" : ["d-0000000000/00000000-0000-0000-0000-000000000000"] : []
}
import {
  for_each = local.group_membership
  to = aws_identitystore_group_membership.example
  id = each.value
}

@jbardin jbardin closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2024
@alecscodehub
Copy link
Author

That solution sounds great @jbardin but i get this error "Unexpected attribute: An attribute named "for_each" is not expected here". Correct me if im wrong but you cant put foreach of count in an import statement.

@jbardin
Copy link
Member

jbardin commented Jun 21, 2024

@alecscodehub, you are using an out of date version of Terraform. Support for for_each was added in v1.7.

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants