I ran into this issue using the Azure DevLabs Terraform extension in Azure Pipelines. It is not possible to specify the subscription Id to use if itβs not the same as the one picked when creating the Service Connection.
The workaround is to pass the subscription Id as an input variable:
Pipeline:
- task: TerraformTaskV2@2
displayName: 'Plan'
inputs:
command: 'plan'
provider: 'azurerm'
environmentServiceNameAzureRM: 'MyServiceConnection'
env:
"TF_VAR_subscription_id": '00000000-0000-0000-0000-000000000000'
Terraform:
provider "azurerm" {
subscription_id = "${var.subscription_id}"
features {}
}