Hi,
I'm using Azure DevOps Pipeline to deploy an infrastructure. One of Terraform modules use local-exec and it is a Powershell script which enables VM SQL Backup. Everything works fine locally from my PC when I'm connected to Azure as a user. The problem appears only in a pipeline. I use a built-in Powershell just to run Connect-AzAccount living with a hope that connection will be kept during all tasks. Unfortunately when it comes to Terraform Apply, during my module deployment, there's an error:
Please provide a valid tenant or a valid subscription.
Resource group 'abcd' could not be found.
Does somebody know how to keep connection with Azure during all tasks? I even tried to run
Set-AzContext
-SubscriptionId "xxxx-xxxx-xxxx-xxxx"
but module doesn't find my subscription.
This is how Powershell task looks like:
$AzureAADClientKey = "***"
$AzureTenantID = "
xxxx-xxxx-xxxx-xxxx
"
$AzureSubscriptionName = "
xxxx-xxxx-xxxx-xxxx
"
$securePassword = ConvertTo-SecureString $AzureAADClientKey -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $AzureAADClientID,$securePassword
$n = Disable-AzContextAutosave -Scope Process
Clear-AzContext -Scope Process
Connect-AzAccount -Credential $credential -TenantId $AzureTenantID -Environment $AzureEnv -ServicePrincipal -SubscriptionId $AzureSubscriptionName