aztfexport icon indicating copy to clipboard operation
aztfexport copied to clipboard

Import multiple resource groups into one state file.

Open Akky8055 opened this issue 2 years ago • 1 comments

Is there any way to import multiple resource groups in one single state.

I tried to --append command but fails.

I ran below commands on single empty dir. Sorry I'm new to this. Aztfy rg "rg name1" aztfy --append rg "rg name2"

Error: flag provided but not defined: -append

Error:

Akky8055 avatar Oct 07 '22 12:10 Akky8055

Hi @Akky8055 try aztfy rg —append:)

stemaMSFT avatar Oct 07 '22 20:10 stemaMSFT

You will also need to differentiate each set of resources by resource group within the generated .tf file otherwise you get the default "res-" prefix generated for each resource imported from each resource group - this will lead to immediate collisions with the "azurerm_resource_group.res-0" resource generated for each resource group

You get around this by invoking -p or --pattern { rg_specific_string } when you invoke aztfy

aztfy rg --append -p { rg_specific_string } { rg_name }

This will allow you to run aztfy rg --append multiple times in the same directory and it will ensure that there are no collisions in the exported/generated code

Of course you will still need to deal with the static/explicit dependencies, and re/create your modules from the exported .tfstate/ generated .tf files - but at least you don;t have to write it all from scratch

Cheers

-=A=-

.

dbhaigh avatar Jan 04 '23 11:01 dbhaigh

@Akky8055 Instead of running the rg subcommand with --append multiple times, you can try the query subcommand to query multiple resource groups under a subscription.

Since we haven't get further response from you, I'll mark this issue as closed for now. Feel free to reopen it if the issue still remains.

magodo avatar May 24 '23 08:05 magodo