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.

1 Like