Closed bcsgh closed 3 years ago
And I'm not the only one who has run into this sort of thing: https://discuss.hashicorp.com/t/refactoring-to-move-a-provider-from-a-child-module-from-the-root-module/10954
Hi @bcsgh,
I think what's going on here is that your child module doesn't have a proxy provider configuration to indicate that your module will be passed an aliased provider named us_east_1
, and so Terraform is getting confused.
If you add a proxy configuration to your child module then I think this should work as you intended:
provider "aws" {
alias = "us_east_2"
# No other arguments, because this is just a proxy that
# will be associated with the parent module's provider
# configuration.
}
Terraform's handling of provider configurations in child modules is unfortunately rather messy because of the efforts it goes to in order to try to remain compatible with the practice of putting provider configurations in modules from Terraform 0.10 and earlier. We are hoping to improve this eventually, but we suspect that doing so will require at least partially breaking compatibility with the older practice, and so we've not attempted to tackle it yet.
I hope the proxy configuration insight above helps you move forward right now. For the purpose of this issue we'll use it to represent that Terraform didn't give good feedback here. It seems like we could perhaps make Terraform produce a special error message in this specific situation (where there's no proxy provider configuration to match with a provider configuration explicitly assigned in the calling module
block), which can hopefully serve as a modest improvement in the short term, rather than waiting for the longer-term design effort.
Better error messages would be a big improvement, regardless of what the situation turns out to be.
To check if I'm understanding you correctly, would a good message say something like:
Resource foo depends on provider bar which could not be found.
It may have been removed from the module, in which case it would
need to be restored in order to manipulate foo, or it may have
been moved into a different module, in which case a proxy provider
needed to be added in it's place.
That said, and I'm working just from memory right now, I think I got the same issue with a proxy provider added. Though that might have been a result of having a un-aliased, default(?) provider (which it seems you can't create a proxy for) which was already inherited from the root. It's not clear what the expected approach for that case is.
FWIW: adding a proxy provider seems to have gotten thing un-stuck. So it seems the bug here is an amusingly misleading error message.
Thanks for confirming, @bcsgh. With that in mind, I've relabeled this issue and changed its title to reflect the focus on improving the error message for now.
Hopefully some bigger changes around how provider passing between modules works will come later, but improving the error message here should ideally not block on the bigger design work.
Thanks!
IMHO, improving error messages is almost always worth doing, even for temporary corner cases. (After all, nothing is as temporary as we hope it will be.)
Random idea: add a flag that causes each error message to kick out a link to a distinct wiki page where more details & examples can be provide and user experience can be accumulated?
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.
Terraform Version
Terraform Configuration Files
Initial state
Run
terraform init ; terraform apply
(which works) Modify the config to:Try to reapply and get this:
Ok, but destroying the object is not an option, it's still in use (true in the non-toy case).
Workaround:
terraform state rm module.m.aws_s3_bucket_object.X
and then re-import the object:Um... WAHT?!
How doe sit even know that exists!?
From here I've tried, renaming the resource, renaming the provider pointing the provider at a different region, making the resource refer to a different object,
rm -rf .terraform
,rm -rf ~/.terraform.d
pkill -9 $NAMES_OF_PROVIDERS
and even rebooting.I've even (in the real-world application, for the cases where I could)
terraform destroy
ed the resources before removing the provider. When I try to edit the config of those resource (which are not associated with any resource) trigger similar errors.I don't see any way to move forward from here.
Expected Behavior
Moving from the discouraged setup of "providers in sub modules" to the encouraged setup of "all providers at the root config" should be viable, preferably without destroying the resources.
Actual Behavior
Terraform seems to have some hidden state somewhere that is tracking which provider was used to create resource and then refusing to allow any modification to it regardless of anything.