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

Importing a resource doesn't work if the module is calling other modules via for_each #30706

Closed
applike-ss opened this issue Mar 21, 2022 · 3 comments · Fixed by #31283
Closed
Labels
bug config confirmed a Terraform Core team member has reproduced this issue core

Comments

@applike-ss
Copy link

Terraform Version

1.1.7

Terraform Configuration Files

https://github.com/applike-ss/tf-import-issue

Debug Output

https://gist.github.com/applike-ss/060f787190d29b707c06a0efccecdaa4

Expected Behavior

resource should be importable, because the for_each does not matter for the resource

Actual Behavior

resource was prepared to import, but import failed with Invalid for_each argument and data.null_data_source.f will be known only after apply

Steps to Reproduce

  • check out repo
  • have an aws account (or exchange the resource against anything else that can be imported that you have an account for)
  • terraform init
  • terraform import 'module.m[0].aws_sns_topic.t' arn:aws:sns:eu-central-1:123456789012:my-topic

Additional Context

References

@applike-ss applike-ss added bug new new issue not yet triaged labels Mar 21, 2022
@jbardin
Copy link
Member

jbardin commented Mar 21, 2022

Hi @applike-ss,

Thanks for filing the issue. The first error is only due to a typo in the command itself, you are passing the number 0 as the for_each key, but keys can only be strings. Quoting the string will avoid the error: 'module.m["0"].aws_sns_topic.t'

The second error however does look like a bug. In essence it's another form of #27934, but since it only manifests in nested modules, we can leave this open as a separate distinct problem for now.

Thanks!

@jbardin jbardin added core config confirmed a Terraform Core team member has reproduced this issue and removed new new issue not yet triaged labels Mar 21, 2022
@applike-ss
Copy link
Author

applike-ss commented Mar 21, 2022

Hi @jbardin,

thank you for your quick response.
In fact both "errors" belonged to the same block.
I tried your quotation and it didn't help.
Looking forward to see #27934 fixed (and derivatives).

Thanks!

@github-actions
Copy link
Contributor

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 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config confirmed a Terraform Core team member has reproduced this issue core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants