jeffhollan / LogicAppTemplateCreator

Script to convert Logic Apps into templates for deployment
MIT License
143 stars 74 forks source link

Get-LogicAppTemplate : Aggregation Exception thrown, One or more errors occurred., first Exception message is: Object reference not set to an instance of an object. #24

Closed coreyperkins closed 6 years ago

coreyperkins commented 6 years ago

Hi,

I have created my own script to pull a list of logic apps from my subscription/rg and spit out the templates for each. I am running into the following error when I get to the Get-LogicAppTemplate call:

Get-LogicAppTemplate : Aggregation Exception thrown, One or more errors occurred., first Exception message is: Object reference not set to an instance of an object., for more information read the output file. At C:\Users\corey\source\repos\LogicAppUtils\ImportLogicAppsFromRG-UsingLogicAppTemplateCreator-cdp.ps1:18 char:2

Here is my script. Also, I have made sure that I am logged in and the subscription is available.

Import-Module C:\PathToCode\LogicAppTemplateCreator\LogicAppTemplate\bin\Debug\LogicAppTemplate.dll!

$logicAppNamePrefixes = @("logic-app-name") foreach ($logicAppNamePrefix in $logicAppNamePrefixes) { $logicAppTemplateOutFilePath = "C:\PathToTemplateFile\" + $logicAppNamePrefix + ".json" $logicAppParamsOutFilePath = "C:\PathToTemplateFile\" + $logicAppNamePrefix + ".parameters.json"

Write-Host $logicAppTemplateOutFilePath
Write-Host $logicAppParamsOutFilePath
Write-Host $logicAppNamePrefix

Get-LogicAppTemplate -LogicApp $logicAppNamePrefix -ResourceGroup "rg" -SubscriptionId "subId" -Verbose | Out-File $logicAppTemplateOutFilePath
#Get-ParameterTemplate -TemplateFile $logicAppTemplateOutFilePath | Out-File $logicAppParamsOutFilePath

}

Thanks for any help!

Corey

MLogdberg commented 6 years ago

Hi, yes the errors are quite bad. Need to fix that but if I look at your script the parameters Resource Group and SubscriptionId must be equal to the ones in the subscription. ResourceGroup is the name and Subscriptionid is the subscription guid. (you have "subid" in the example provided) Get-LogicAppTemplate -LogicApp $logicAppNamePrefix -ResourceGroup "rg" -SubscriptionId "subId" -Verbose | Out-File $logicAppTemplateOutFilePath

coreyperkins commented 6 years ago

@MLogdberg I hacked subid in there, so as to not be passing my real one to the GitHub masses. :)

MLogdberg commented 6 years ago

@coreyperkins ahh good you got that. Can you debug it?

coreyperkins commented 6 years ago

@MLogdberg I can, though I am just getting familiar with the units tests. I have tweaked the AzureResourceIdGetSubscriptionTest test to use my sub and rg and it was successful. Which test should I hit for template gen?

MLogdberg commented 6 years ago

Hi, that test is not ment for that purpose. I would still say that the problem is authentication (will add an pull request for adding better information) but are you having multiple tenants connected to the user? In the Azure Portal you can click on the top right part and see the tenants you have access to and the tenant name used with the script

coreyperkins commented 6 years ago

Dead on, auth issue. Worked after we got our Azure AD setup correct. Thanks! And, I'll be glad to check out that PR if you need.