AzureAD - Reading Service principals inside Microsofts network

I have a set of terraform scripts that I am trying to move from local to pipeline execution. Everything works locally. When I try and run via a pipeline (Azure CLI or powershell on Managed Devops Pool) I get an error trying to retrieve the service principal.

Error: Listing service principals for filter “displayName eq ‘DevOpsInfrastructure’”

TF:
data “azuread_service_principal” “sp” {
display_name = “DevOpsInfrastructure”
}

resource “azurerm_role_assignment” “reader” {
scope = var.hub_vnet.id
role_definition_name = “Reader”
principal_id = data.azuread_service_principal.sp.object_id
}

resource “azurerm_role_assignment” “network” {
scope = var.hub_vnet.id
role_definition_name = “Network Contributor”
principal_id = data.azuread_service_principal.sp.object_id
}

As stated I’m confused why I can run it locally but not in a pipeline.

Any help would be much appreciated.

Mike