My Release pipeline was working very fine until I deleted app registration/Service Principal from UI and created a new one using the below command.
az ad sp create-for-rbac --name <Name of Service Principal> --password <Password>
I updated the values which I got from the above in "Variable Groups" below which is linked to release pipelines
However when I get terrafor plan task which is defined as below:
Terraform plan -out main.plan -var "ARM_SUBSCRIPTION_ID=$(TF_VAR_ARM_SUBSCRIPTION_ID)" -var "ARM_CLIENT_ID=$(TF_VAR_ARM_CLIENT_ID)" -var "ARM_CLIENT_SECRET=$(TF_VAR_ARM_CLIENT_SECRET)" -var "ARM_TENANT_ID=$(TF_VAR_ARM_TENANT_ID)"
I get the error message below:
* provider.azurerm: Unable to list provider registration status, it is possible that this is due to invalid credentials or the service principal does not have permission to use the Resource Manager API, Azure error: azure.BearerAuthorizer#WithAuthorization: Failed to refresh the Token for request to https://management.azure.com/subscriptions/***/providers?api-version=2016-02-01: StatusCode=400 -- Original Error: adal: Refresh request failed. Status Code = '400'. Response body: {"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier '***()' was not found in the directory '***'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.\r\nTrace ID: 7a1e3f3a-5171-4044-b59a-49a78d3df300\r\nCorrelation ID: f61d0e14-ecf7-45b9-bbc7-e357ddb7b1dd\r\nTimestamp: 2019-03-12 10:22:16Z","error_codes":[700016],"timestamp":"2019-03-12 10:22:16Z","trace_id":"7a1e3f3a-5171-4044-b59a-49a78d3df300","correlation_id":"f61d0e14-ecf7-45b9-bbc7-e357ddb7b1dd","error_uri":"https://login.microsoftonline.com/error?code=700016"}
2019-03-12T10:22:16.4925828Z
Just before this task that is cmd task which executes az account login with Service Principal. In log output, I can see clearly output of az account show so why this task is not working?
Output of CMD task,
2019-03-12T11:58:05.4615044Z Environment variable -x not defined
2019-03-12T11:58:05.4615608Z ***
2019-03-12T11:58:05.4667686Z ***
2019-03-12T11:58:05.4668423Z ***
2019-03-12T11:58:05.4669112Z ***
2019-03-12T11:58:05.4669557Z "Subscription ID=> ***"
2019-03-12T11:58:48.5462240Z [
2019-03-12T11:58:48.5463710Z {
2019-03-12T11:58:48.5464432Z "cloudName": "AzureCloud",
2019-03-12T11:58:48.5464946Z "id": "***",
2019-03-12T11:58:48.5465917Z "isDefault": true,
2019-03-12T11:58:48.5469154Z "name": "Visual Studio Enterprise",
2019-03-12T11:58:48.5469568Z "state": "Enabled",
2019-03-12T11:58:48.5469843Z "tenantId": "***",
2019-03-12T11:58:48.5470058Z "user": {
2019-03-12T11:58:48.5470290Z "name": "***",
2019-03-12T11:58:48.5470496Z "type": "servicePrincipal"
2019-03-12T11:58:48.5471388Z }
2019-03-12T11:58:48.5471648Z }
2019-03-12T11:58:48.5471999Z ]
It's definition is as below:
echo $(TF_VAR_ARM_SUBSCRIPTION_ID)
echo $(TF_VAR_ARM_TENANT_ID)
echo $(TF_VAR_ARM_CLIENT_SECRET)
echo $(TF_VAR_ARM_CLIENT_ID)
echo "Subscription ID=> $(TF_VAR_ARM_SUBSCRIPTION_ID)"
az login --service-principal -u $(TF_VAR_ARM_CLIENT_ID) -p $(TF_VAR_ARM_CLIENT_SECRET) --tenant $(TF_VAR_ARM_TENANT_ID)
az account show
Before I was able to provision resource without any issue.