Azure / aztfexport

A tool to bring existing Azure resources under Terraform's management
https://azure.github.io/aztfexport/
Mozilla Public License 2.0
1.63k stars 190 forks source link

Import Resource groups + resources #545

Closed paramonovnik closed 3 months ago

paramonovnik commented 4 months ago

Hi,

We need to import all resource groups (whether empty or not - doesn't matter) as well as all virtual networks + subnets from around 100 subscriptions. Is there a query that would allow to do it? --include-resource-group only includes an RG in the mapping file if there's at least one other exported resource, so this doesn't work. Resource groups cannot be queried using query option as they're not in "Resources" table in resource graph. Are there any options to achieve this?

paramonovnik commented 4 months ago

i see that default query mode Makes an api call starting with the following: " Resources | where" can it be overwritten?

stemaMSFT commented 4 months ago

Unfortunately @paramonovnik the tool works on a subscription scope at the broadest level. Luckily, you can specify the type parameter to be a resource group, a virtual network, or a subnet, and the query should return all relevant resources for the query. If you perform this operation in a script across each of your resource IDs, that should get your job done in a relatively straightforward manner. Otherwise, the "Resources | where" logic is not overwritable to my understanding.

magodo commented 3 months ago

With #522, you shall be able to use your way to query out all the resource ids you want to export and record them in a file. Then use aztfexport resource @/path/to/file to get all of them exported, as long as your principal has the proper role in those subs.