How do I import a resource while also including dependencies? If I specify an attribute from another resource, and then import it by id, there is no dependency that shows up in state.
My use case is migrating an existing set of infrastructure to TF management. I did this by:
- Create a blank environment that is managed by TF
- Create each piece from the prod env in the blank one using HCL
- Verify that the resource layout / attributes of the two environments are identical
- Back up the copy-cat tfstate, start with no state and import each resource from prod.
This worked great, except that when I diff the copy-cat state and the new state that is created after I imported everything, the new state is missing all the "dependencies": []
blocks.
I verified that this is an issue by running terraform destroy -target [critical piece]
against both states. The original copy cat state shows that I would be destroying pretty much all of the infrastructure, whereas the new imported state shows that I would only be destroying the piece specified.
Is there a way to import resources while intuiting its dependencies, the same way as it would be if it were simply created?