Is is possible to import multiple resources at once ? [custom provider]

I have a setup like

resource vpc v1 {

resource subnet sub1 {
resource server s1 {
   vpc       = vpc.v1
   subnet    = subnet.s1

In case we lose the state file, is there a way to import all 3 at once or automate this type of requirement ?

If you mean the terraform import command then no, it’s a building block for importing to only a single resource instance at a time.

However, you can potentially write some other software which automates discovering multiple objects (directly using the same API the provider would use) and either generating a series of terraform import command lines or runs those commands directly itself, depending on your needs. That software can then encode some special policy for understanding what should and should not be included in that sort of bulk import, which typically varies depending on the use-case.


I struggled with something similar so I will drop what I found here, perhaps it helps someone else.
I would recommend using terraformer for these cases, it helps to have a good sense of your existing infrastructure and it generates a state for you, it is not bulletproof but indeed helpful GitHub - GoogleCloudPlatform/terraformer: CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code