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.