-
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 configuration cannot depend on data sources during import #27934
Comments
These instructions are not exactly correct. Simply doing a targeted apply of a null_resource doesn't work. You have to do a targeted apply of the data sources that are needed to configure the provider. Only then will you be able to import state using those providers. |
Hi @llamahunter, the mention of the null resource is only to create a state if none exists at all, and targeting should not be required to read any data sources. If you however have managed resources which are required to do this, then those will need to be targeted separately for creation. |
In this case, there was existing state. However, providers had been added to the top level, as they had been removed from modules. Needed to import some resources that changed names in the shuffle, but those resources depended on the new providers added at the top, which in turn depended on data sources also added to the top. Doing targeted applys of the data sources 'fixed' things so that the providers could be used during import. |
What is the workaround? What does
|
I wonder if the
In this case |
If I'm not mistaken it's not just that a provider used during import cannot depend on data sources for its configuration". It's more that none of the provider configurations may depend on data sources if doing a So for example in my case I have 3 provider blocks:
I'm trying to import a resource
But as mentioned this can be workarounded by doing a targetted apply for the required data sources:
|
It might vary by backend, but with an s3 backend at least, I didn't need any resources to create the state. Simply doing a no-op apply of the provider + data was sufficient to allow me to import the resource. |
Would like to see a solution that supports an import during a cold start. I'm learning with |
In my case my provider depended on a
Terraform import fails with
I had to do 2 ugly hacks to get import working.
Then in modules using the provider I had to pass the aliased provider.
I'm using |
Does anyone has a workaround for this problem? |
@iosifnicolae2, I split my project into multiple states like |
My setup relied on remote variables that didn't work with this either. As a hacky workaround, I commented out all dynamic things (like vars/data) it complained about, then replaced the var.xxx variables with hardcoded values (passed vars or passed through env didn't work). Once it passed I switched everything back. |
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. |
As documented in Import: Provider Configuration, a provider used during import cannot depend on data sources for its configuration*.
As of v0.14, data sources can now be handled entirely during planning, which in principle works similarly to the import process. This means that it should be possible to expand and evaluate required data sources during import as well, as long as they themselves do not depend on any resource data which is not contained within the state.
*This shortcoming is no longer entirely true, a data source can be read from the existing state. The workaround for this case is to add the data source and refresh it immediately before running import. A state is required to refresh however, so if there has yet to be any created, applying a single
null_resource
will allow therefresh
to complete, reading the data source into the state.References:
This was mentioned in the comments of #13018, but the original cases presented there are no longer relevant in current releases.
The text was updated successfully, but these errors were encountered: