aztfexport icon indicating copy to clipboard operation
aztfexport copied to clipboard

panic: runtime error: invalid memory address or nil pointer dereference

Open RakhilRavindran007 opened this issue 3 years ago • 6 comments

Hello Team,

I'm getting below error when I tried to run aztfy command to import all resources inside a resource group. this resource group has around 500 resources inside it.

Azure Terrafy

panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x0 pc=0x1660809]

                                                                                                                     goroutine 176 [running]:
                                                                                                                                             github.com/magodo/azlist/azlist.listDirectChildResource({0x2c4b110, 0xc000038100}, 0xc003199780, 0x10000c0032c7290?, {{0x2c4f818?, 0xc003458cd0?}, 0xc00273bce0?})
                                                                    github.com/magodo/[email protected]/azlist/azlist.go:347 +0x129
                                                                                                                                                           github.com/magodo/azlist/azlist.ListChildResource.func2()
                                                                                                                                                                                                                            github.com/magodo/[email protected]/azlist/azlist.go:285 +0x47
                                                                     github.com/magodo/workerpool.(*workPool).Run.func1(0x0?)
                                                                                                                                    github.com/magodo/[email protected]/workerpool.go:75 +0x99
                                                                                                                                                                                                                          created by github.com/magodo/workerpool.(*workPool).Run
                                            github.com/magodo/[email protected]/workerpool.go:66 +0x5d

RakhilRavindran007 avatar Oct 11 '22 21:10 RakhilRavindran007

@RakhilRavindran007 Thank you for submitting this! I've made a fix in the https://github.com/magodo/azlist project. However, I don't have the environment the reproduce this issue, as I have tried to use azlist to list all the resources under my subscription, which won't trigger this panic.

Could you please verify that using the latest azlist, the issue is fixed on your side? You can simply install it via go install github.com/magodo/azlist@latest. Then run it via azlist 'resourceGroup =~ "YOUR_RG_NAME"'. Once you confirmed it works, I'll update the dependency in aztfy.

magodo avatar Oct 12 '22 02:10 magodo

Hello @magodo I followed the above steps and installed latest version of azlist. however when I tried to run it via azlist 'resourceGroup =~ "MY_RG_NAME"' im getting required flag missing error as show below. image

RakhilRavindran007 avatar Oct 12 '22 07:10 RakhilRavindran007

You'll have to set the subscription id, either via -s or the env var ARM_SUBSCRIPTION_ID.

magodo avatar Oct 12 '22 08:10 magodo

Hi @magodo Thanks for your prompt reply. I tried to run the command which includes the subscription id. Im getting a bad request output when run the command. please see below screenshot. image

RakhilRavindran007 avatar Oct 12 '22 09:10 RakhilRavindran007

That's weired... It works for me:

💤  azlist  'resourceGroup =~ "aztfy-vmdisk"'            
/subscriptions/xxxx/resourceGroups/AZTFY-VMDISK/providers/Microsoft.Compute/disks/aztfy-test-test_OsDisk_1_3ef6711919624d5594387b69adc35634
/subscriptions/xxxx/resourceGroups/AZTFY-VMDISK/providers/Microsoft.Compute/virtualMachines/aztfy-test-test
/subscriptions/xxxx/resourceGroups/AZTFY-VMDISK/providers/Microsoft.Compute/virtualMachines/aztfy-test-test/extensions/Microsoft.Azure.Security.Monitoring.AzureSecurityLinuxAgent
/subscriptions/xxxx/resourceGroups/aztfy-vmdisk/providers/Microsoft.Compute/disks/aztfy-test-test
/subscriptions/xxxx/resourceGroups/aztfy-vmdisk/providers/Microsoft.Network/networkInterfaces/aztfy-test-test
/subscriptions/xxxx/resourceGroups/aztfy-vmdisk/providers/Microsoft.Network/networkSecurityGroups/NRMS-clhxdfaurwj2oaztfy-test-test-internal
/subscriptions/xxxx/resourceGroups/aztfy-vmdisk/providers/Microsoft.Network/networkSecurityGroups/NRMS-oyhsp3ghi6phaaztfy-test-test
/subscriptions/xxxx/resourceGroups/aztfy-vmdisk/providers/Microsoft.Network/virtualNetworks/aztfy-test-test

I suspect it might because the quote around your rg name is not reserved by the powershell?

magodo avatar Oct 12 '22 09:10 magodo

Hi @magodo I 've faced the identical issue than @RakhilRavindran007
When would you be able to update aztfy with this fix on azlist ?

Thanks

teerakdv avatar Oct 14 '22 17:10 teerakdv

Assuming this is merged into main, I am still seeing this issue. I can list resources for an RG with azlist but aztfy still throws panic: runtime error: invalid memory address or nil pointer dereference. Is there a timeframe on this fix?

bhmahler avatar Nov 09 '22 18:11 bhmahler

@bhmahler Yes it is merged in main. Did you install it from source? Would you please check the output of go version -m ~/go/bin/aztfy | grep vcs.revision?

magodo avatar Nov 10 '22 01:11 magodo

I am running on windows so no grep but I installed with go install github.com/Azure/aztfy@latest I do not see vcs.revision anywhere in the output of go version -m ... The aztfy version is mod github.com/Azure/aztfy v0.9.0 h1:+gcSgOqyzAFpCONt/gbuStEP6A/dXnuyOAJ5bKvWA/w=

I am trying to build from the source but having issues with stthe complied app being blocked. Working on getting that resolved and will test with this version once I do.

UPDATE: When running from the compiled source it appears to be working correctly

bhmahler avatar Nov 10 '22 14:11 bhmahler

@bhmahler go install github.com/Azure/aztfy@latest installs the latest release, while go install github.com/Azure/aztfy@main install the main branch (i.e. the latest version).

magodo avatar Nov 11 '22 00:11 magodo

Installing from the main branch instead of the latest release solved my issue. Thanks @magodo

najx avatar Jan 31 '23 18:01 najx