Running powershell from VS Code to do Connect-AzureRmAccount and run New-AzureRmResource ends up with error RRS feed

  • Question

  • Hi

    I am able run my powershell script to do Connect-AzureRmAccount passing clientId,Secret, tenentId, subscriptionId. but the nest steps to run New-AzureRmResource fails with error below

    New-AzureRmResource : Object reference not set to an instance of an object.

    I can run the complete script successfully on Powershell ISE or powershell. it errors out when use terraform to call the powershell script. I can see the Connect-AzureRmAccount was executed successfully but the next command failed with the error.

    Any idea what needs to be added to make this work?

    Wednesday, July 24, 2019 8:00 PM

All replies

  • Hi ChethanRavula,

    Thanks for reaching out!

    This issue arises when your service principal does not have access to your subscription. Please make sure you provide proper role to your service principal.

    I execute the below script from Terraform and it seems to be working fine:

    $azureAplicationId ="Azure AD Application Id" $azureTenantId= "Your Tenant Id" $azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force $psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword) Connect-AzureRmAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal

    New-AzureRmResource -Location "West US" -Properties @{test="test"} -ResourceName testresource -ResourceType microsoft.web/sites -ResourceGroupName <resource_group_name> -Force

    Hope this helps!

    Wednesday, July 31, 2019 11:03 AM
  • Let us know if there is anything else related to this thread that we can assist you with, else please feel free to mark and close this out if the above response has been of help! Thanks again for reaching out!
    Monday, August 5, 2019 6:18 AM