-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Terraform v1.10.0 rejects for_each on imports in some valid cases #36111
Comments
Hi @dancorne Thanks for filing the issue! This appears to be working as designed, and matches the spec for implementation (hence the error message It looks like you are trying to use the |
Thanks for the response @jbardin, it did sound as-intended but where can I find the spec out of interest? I'm not clear one what should and shouldn't be supported now, and it's worked this way for a while so it seems like a regression. Conditional imports like the example above are our main situation, but I can think of others that won't work now which did before. For example, to manage a number of AWS auto-scaling groups with different AMIs a simple way to do that would be to have a
|
Thank @dancorne, I think you're right, that definitely does look like an oversight when importing into a module. I'm going to check if it's safe to just skip that validation for now, since wherever that validation lived before didn't appear to work either. |
This is a regression for us. This was working fine in 1.9.x as a way to have conditional imports. A blocker for us upgrading to 1.10.x at the moment. |
@jbardin - is there somewhere that documents the scenarios where It's tremendously useful for conditional imports by in your comment you mentioned that it's "not fully supported". I'm keen to dig into that further to understand how to stay within supported scenarios :-) |
I spent a bunch of time building out a tool that would generate conditional imports for us, and it was working great on 1.9.6! Then we upgraded to 1.10.0 and it broke :( IMO this was a great feature, and the regression is really disappointing. Will #36136 fix the regression? |
@skeggse, #36136 should have already fixed the regression in 1.10.1! If you still have something which isn't working, please file a new issue with the details. @stuartleeks, There is no way to always handle an import which may or may not already exist. Leveraging an existing data source which can successfully return zero-or-more results can work when combined with |
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. |
Terraform Version
Terraform Configuration Files
In feature/main.tf:
Debug Output
https://gist.github.com/dancorne/e5e0d2b7120eff24acc50a3b62b0816d
Expected Behavior
Terraform should optionally import resources, regardless of whether they use
count
/for_each
.Actual Behavior
Steps to Reproduce
Using the two files above,
terraform validate
orterraform plan
will fail, whether thefeature_switch
flag is enabled or disabled.Additional Context
It looks like Terraform in v1.10.0 is pickier about then resource graph when importing. This will create challenges when trying to optionally import resources e.g. as part of a migration from one root module to another.
The error message suggests any
import
blocks usingfor_each
need the resource to also usefor_each
(orcount
), however the example above shows a resource within a module usingfor_each
isn't considered acceptable.I there's two possible issues here:
for_each
on an import a resource that's not also usingfor_each
/count
. The error message suggests this is intentional, but perhaps the use-case of usingfor_each
to be a conditional wasn't considered? In those circumstances 0 or 1 instances ofimport
matching a single non-conditional resource makes sense when you want to import something that might or might not be there, eg depending on the AWS account you're applying to.count
/for_each
is used on a module the resource is in. Thi really complicates any use ofcount
/for_each
on modules where imports are used.Interestingly, the example is trivial to workaround: it's possible to add
count = 1
to the resource and update the import resource to use[0]
and it works as expected. I don't think this should be required for all resources in a module usingfor_each
though.References
This looks like the relevant PR where the behaviour changed: #35516
The text was updated successfully, but these errors were encountered: