Using Azure AD provider 3.7.0. While trying to create app registration or service principal getting error - Timed out whilst waiting for new service principal to be replicated in Azure AD.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.116.0, < 4.21.1"
}
azuread = {
source = "hashicorp/azuread"
version = "~> 3.7.0" #earlier version was 3.1.0
}
azuredevops = {
source = "microsoft/azuredevops"
version = ">= 1.6.0"
}
}
backend "azurerm" {}
}
# Create app registration
resource âazuread_applicationâ âappregâ {
display_name = var.application_name
prevent_duplicate_names = true
sign_in_audience = âAzureADMyOrgâ
lifecycle {
ignore_changes = \[ required_resource_access, api, web \]}
owners = [data.azurerm_client_config.current.object_id]
}
resource âtime_sleepâ âwait_for_replication_60sâ {
depends_on = [azuread_application.appreg]
create_duration = â60sâ
}
# Set rotation for spn secret
resource âtime_rotatingâ âsecret_timeâ {
rotation_months = var.secret_rotation_in_months # default is 6 months
}
# Create service principal for this app registration
resource âazuread_service_principalâ âspnâ {
client_id = azuread_application.appreg.client_id
use_existing = true
depends_on = [time_sleep.wait_for_replication_60s]
}
â Error: Provider produced inconsistent result after apply
â When applying changes to
module.data.module.project[0].module.spn[0].module.spn.azuread_application.appreg,
â provider "provider[\âTerraform Registry"]â produced
â an unexpected new value: Root object was present, but now absent.
â This is a bug in the provider, which should be reported in the providerâs
â own issue tracker.
â Error: Timed out whilst waiting for new service principal to be replicated in Azure AD
â with module.data.module.project[0].module.spn2[0].module.spn2.azuread_service_principal.spn,
â on .terraform\modules\data\spn\main.tf line 45, in resource âazuread_service_principalâ âspnâ:
â 45: resource âazuread_service_principalâ âspnâ {
â unexpected status 404 (404 Not Found) with error: Request_ResourceNotFound:
â Resource âb5fexxxx-xxxx-2343-z3214-xxxxxxxxxxxxxxxxâ does not exist or one of
â its queried reference-property objects are not present.