Skip to content

Create azuread_application periodically fails - unexpected status 409 (409 Conflict) with error: Error_MsaAppDoesNotExist: The corresponding MSA application does not exist.Β #1764

@hkrazure

Description

@hkrazure

Community Note

  • Please vote on this issue by adding a πŸ‘ reaction to the original issue to help the community and maintainers prioritise this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritise the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureAD Provider) Version

I have tried this with multiple version of terraform and multiple versions of the azuread provider - they are all unstable:

terraform: 1.11.0, 1.12.0, 1.12.2, 1.13.0-rc1, 1.13.0
azuread: 2.51.0, 3.0.0, 3.1.0, 3.5.0

Affected Resource(s)

  • azuread_application

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "4.0.0"
    }
    azuread = {
      source  = "hashicorp/azuread"
      version = "3.5.0"
    }
  }
  required_version = ">= 1.1.0"
}
 
provider "azurerm" {
  features {}
  resource_provider_registrations = "none"
  subscription_id                 = "XXXXXXXXXXX"
}
 
provider "azuread" {
  tenant_id     = "XXXXXXXXXXX"
  client_id     = "XXXXXXXXXXX"
  client_secret = "XXXXXXXXXXX"
}
 
data "azuread_application_published_app_ids" "well_known" {}
 
resource "azuread_application" "service-application" {
  display_name = "test"
  sign_in_audience = "AzureADandPersonalMicrosoftAccount"
 
  api {
    requested_access_token_version = 2
  } 
}

Debug Output

https://gist.github.com/hkrazure/fbb09c916b38a1d7789199873318b68f

Panic Output

Expected Behavior

The app registration should be created every time instead of failing some of the time.

Actual Behavior

It fails with the following message:

β”‚ unexpected status 409 (409 Conflict) with error: Error_MsaAppDoesNotExist:
β”‚ The corresponding MSA application does not exist.

Apparently creating an app registration resource results in two calls from terraform - a post and a patch.

It appears that the patch request fails because azure schedules creating some resources asynchronously - but this is not awaited before the patch request is executed which results in the failure.

Steps to Reproduce

  1. Initialize terraform
  2. Run terraform plan
  3. Run terraform apply
  1. terraform apply

Important Factoids

This is an issue with sign_in_audience = "AzureADandPersonalMicrosoftAccount".

It seems to work with other sign_in_audience values.

But we need this specific one in our setup.

References

I can see there is an issue for microsoft graph that fails with the samme message:

microsoftgraph/msgraph-sdk-powershell#3380

  • #0000

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions