-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Provider is initialised with stale data source attribute #16559
Comments
Hi @camjackson! Sorry for this confusing behavior. As some context for what's going on here, a normal
Data sources are dealt with during the "refresh" step where possible (that is, when their configuration doesn't depend on something that is The intended behavior is that the usual graph machinery in Terraform will ensure that the data source is refreshed before the provider is instantiated, since the provider refers to a result from the data source. Therefore the behavior you've seen here seems like a bug. It may be the case that the To determine if that theory holds water it'd be necessary to see the sequence of operations in the debug log, but I understand that you don't want to share it in its entirety. If you'd be willing, it'd be useful to see the log lines of the following type, in their relative order within your log:
(Some of these are I know that's a lot 😖 . I put together this
This result will include the names of modules and resources as part of their resource addresses, but should otherwise just be Terraform-specific details that are hopefully not concerning to share. |
Hi @camjackson, In the mean time I did some design work around a potential solution to this over in #17034. There is still some more work to do there to finalize that design, but rather than having two issues that cover the same problem I'm going to close this one out just to consolidate. We're not working on #17034 directly at this time due to attention being elsewhere, but we'll post updates there when we have them. Thanks for reporting this, and sorry for the long silence. |
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. |
What I'm trying to do
In my project I have a module that creates the base infrastructure (instance, networking, etc), and then a separate one that deploys Docker images/containers onto the instance. Something like:
main.tf
base/main.tf
: creates the instance and exposes its IDapps/main.tf
: Takes in the ID, looks up the instance, and gives its IP to the docker providerThe reason I pass the ID around and not the IP directly, is that the
apps
module needs several attributes of the instance. Rather than pass them all in one by one, I can save a lot of code by passing just the ID and deriving everything else from the data source.The problem
The instance has been recreated, so its ID and IP have changed, but the Docker provider is still using the old IP address.
When I do
terraform apply --target module.base
, and get it to output the instance ID at the top level, I can see the new, fresh ID. But when I do justterraform plan
orterraform apply
, as soon as it tries to initialise the Docker provider, I get an error message like:I have verified that the IP shown in the console is the IP of the previous, terminated instance.
I'm guessing that this is a similar chicken-and-egg problem to #2430. I was already aware that all providers have to be initalised before any resources can be created, which is why I've implemented this particular module structure in the first place. What's news to me here is that providers also have to be initialised before any data sources can be refreshed, which would seem to make it a very bad idea for providers to depend on data sources.
Terraform Version
Terraform v0.10.8
Debug Output
The debug output and state file both contain sensitive data, so I won't post them online. However I can see that both the old and new IDs and IPs are mentioned there. It does look like a
DescribeInstances
action is done on the new ID, and the new IP is returned. It's just not making its way through to the Docker provider.Workaround
I think I have two options here, one easy, and one robust. The easiest path forwards is to just hard-code the new IP address into the Docker provider for a single
terraform apply
. That gets me out of the rut I'm in and I can move on. But the problem will come back whenever the instance changes again. A more robust solution would be to pass the IP address in directly, rather than looking it up from the data source. Which is annoying, but perhaps necessary in this case.The text was updated successfully, but these errors were encountered: