1
votes

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.

1
Not clear about your question, do you mean how to use the terraform modules for Azure?Charles Xu

1 Answers

0
votes

Update: Have found the issue
The issue was when importing, I didn't specify the module. so the code is
terraform import module.environment1.azurerm_resource_group.RESOURCE /subscriptions/xxx/resourceGroups/MYRESOURCEGROUP