Search code examples
azure-devopsazure-active-directoryazure-pipelinesterraform-provider-azure

Azure app registration creation error through terraform Azure Devops yml pipeline


I have very simple terraform code.

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=2.46.0"
    }

    azuread = {
      source  = "hashicorp/azuread"
      version = "~> 2.0.0"
    }

  }
}

provider "azurerm" {
  features {}
}

provider "azuread" {
  tenant_id       = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

terraform {
  backend "azurerm" {
      resource_group_name = "xxxx"
      storage_account_name = "xxxxxxxxx"
      container_name = "xxxxxxxxxxxxx"
      key = "xxxxxxxxxxxxxxxxx"
      
    }
 }

data "azuread_client_config" "current" {}

resource "azurerm_resource_group" "test" {
  name     = "test-rg-005"
  location = "East US"
}


resource "azuread_application" "example" {
  display_name = "Example-app"
}

However when i run this through yml pipeline on azure devops, i am getting this error during apply stage.

Plan: 1 to add, 0 to change, 0 to destroy.

azuread_application.example: Creating...

│ Error: Could not create application
│ 
│   with azuread_application.example,
│   on terraform.tf line 42, in resource "azuread_application" "example":
│   42: resource "azuread_application" "example" {
│ 
│ json.Marshal(): json: error calling MarshalJSON for type
│ msgraph.Application: json: error calling MarshalJSON for type
│ *msgraph.Owners: marshaling Owners: encountered DirectoryObject with nil
│ ODataId

##[error]Error: The process '/opt/hostedtoolcache/terraform/1.0.5/x64/terraform' failed with 
exit code 1

Any clue will be helpful, not really clear what this error is about?

Thanks.


Solution

  • There is a bug in azure Active directory provider after an MSFT update. This is impacting any azure ad provider usage creating new resources, however it seems to be working on already deployed resources, i.e. changing and upgrading the configurations of already deployed resource within azure ad. Following is the link for the bug updates.

    https://github.com/hashicorp/terraform-provider-azuread/issues/588