I have recently tried to set up a service connection to a second subscription, I have it working on the first subscription fine and has been working for seven months and still is working. But when I give the Service Principal Application access to the new subscription the pipeline fails and says it can not see the Resource Group. This is on the Terraform Initialise step.
I have given contributor access to the Service Principal on the Subscription Level and also for good measure have given contributor access to the Service Principal on the actual resource group its self.
This is the error that I am getting:
Initializing the backend...
Successfully configured the backend "azurerm"! Terraform will automatically
use this backend unless the backend configuration changes.
╷
│ Error: Failed to get existing workspaces: Error retrieving keys for Storage Account "nsterraformstatestorage": storage.AccountsClient#ListKeys: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceGroupNotFound" Message="Resource group 'TerraformBackendForCICTesting' could not be found."
│
│
╵
##[error]Error: The process '/opt/hostedtoolcache/terraform/1.0.4/x64/terraform' failed with exit code 1
I have followed this post in the past to setup the service connection: https://sabirmohamed.com/how-to-create-a-service-connection-in-the-azure-devops/
I do believe both subscriptions are in the same tenant.
I must be missing something as I am sure one service principal can work across multiple subscriptions.