So a simplified structure of projects for terraform is the following
environemnt1/
-main.tf (includes module, backend, environment)
environemnt2/
-main.tf
modules/
resources (includes resources, variables etc)
The case is attempting to deal with the situation where the state file is lost.
When using important for say environment 1, the resource will have to be in the environment (main.tf). I can successfully import the resource into this environment. Despite this, the normal pattern, feeds the environment into the resource (module source is resource, allowing for generic resource files).
So what we are looking to do, is import the resource for that environment but keep the code generic (i.e. have resource in the modules) rather than in each environment file. Has anyone worked out how to correctly do this?
I've tried to implement the code in the environment, successfully imported the resource into the state. However, it will replace the existing resource if I move the code back to the environment.