azure - json.Marshal() : json: error calling MarshalJSON for type msgraph. 应用程序

标签 azure azure-active-directory terraform terraform-provider-azure

必须进行哪些特定语法或配置更改才能解决以下 terraform 无法创建 azure_application 实例的错误?

代码:

运行 terraform apply 时触发错误的 terraform 代码如下:

variable "tenantId" { }
variable "clientId" { }
variable "clientSecret" { }
variable "instanceName" { }

terraform {
  required_providers {
    azuread = {
      source  = "hashicorp/azuread"
      version = "2.5.0"
    }
  }
}

provider "azuread" {
  tenant_id       = var.tenantId
  client_id       = var.clientId
  client_secret   = var.clientSecret
}

resource "azuread_application" "appRegistration" {
  display_name = var.instanceName
  app_role {
    allowed_member_types = ["User", "Application"]
    description          = "Admins can manage roles and perform all task actions"
    display_name         = "Admin"
    enabled              = true
    id                   = "1b19509b-32b1-4e9f-b71d-4992aa991967"
    value                = "admin"
  }
}

错误:

使用 terraform apply 运行上述代码所产生的错误和日志输出是:

2021/10/05 17:47:18 [DEBUG] module.ad-admin.azuread_application.appRegistration:
 apply errored, but we're indicating that via the Error pointer rather than returning it:
 Could not create application: 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

2021/10/05 17:47:18 [TRACE] EvalMaybeTainted: module.ad-admin.azuread_application.appRegistration encountered an error during creation, so it is now marked as tainted
2021/10/05 17:47:18 [TRACE] EvalWriteState: removing state object for module.ad-admin.azuread_application.appRegistration
2021/10/05 17:47:18 [TRACE] EvalApplyProvisioners: azuread_application.appRegistration has no state, so skipping provisioners
2021/10/05 17:47:18 [TRACE] EvalMaybeTainted: module.ad-admin.azuread_application.appRegistration encountered an error during creation, so it is now marked as tainted
2021/10/05 17:47:18 [TRACE] EvalWriteState: removing state object for module.ad-admin.azuread_application.appRegistration
2021/10/05 17:47:18 [TRACE] vertex "module.ad-admin.azuread_application.appRegistration": visit complete

2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin.output.application_id (expand)" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin.azuread_service_principal.appRegistrationSP" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "output.application_id" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin.output.appId (expand)" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin.azuread_service_principal_password.appRegistrationSP_pwd" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "output.appId" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin.azurerm_role_assignment.appRegistrationSP_role_assignment_vault" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin.azurerm_role_assignment.appRegistrationSP_role_assignment" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin.provider[\"registry.terraform.io/hashicorp/azuread\"] (close)" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin.provider[\"registry.terraform.io/hashicorp/azurerm\"] (close)" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "module.ad-admin (close)" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2021/10/05 17:47:18 [TRACE] dag/walk: upstream of "root" errored, so skipping
2021/10/05 17:47:18 [TRACE] statemgr.Filesystem: creating backup snapshot at terraform.tfstate.backup
2021/10/05 17:47:18 [TRACE] statemgr.Filesystem: state has changed since last snapshot, so incrementing serial to 391
2021/10/05 17:47:18 [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate
2021/10/05 17:47:18 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info

Error: Could not create application

  on ..\..\..\..\modules\ad-admin\active-directory.tf line 69, in resource "azuread_application" "appRegistration":
  69: resource "azuread_application" "appRegistration" {

json.Marshal(): json: error calling MarshalJSON for type msgraph.Application:
json: error calling MarshalJSON for type *msgraph.Owners: marshaling Owners:
2021/10/05 17:47:18 [TRACE] statemgr.Filesystem: unlocked by closing terraform.tfstate
encountered DirectoryObject with nil ODataId

terraform -version 给出:

Terraform v1.0.8 在 windows_amd64 上

最佳答案

这是一个错误,报告为 GitHub 问题:

OP中问题的解决方案是将required_providers block 中的版本从2.5.0升级到2.6.0上面OP中的代码如下:

terraform {
  required_providers {
    azuread = {
      source  = "hashicorp/azuread"
      version = "2.6.0"
    }
  }
}

关于azure - json.Marshal() : json: error calling MarshalJSON for type msgraph. 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69459069/

相关文章:

azure - 使用托管标识从逻辑应用调用受 Azure AD 保护的 API

javascript - 通过代码设置应用程序注册 (Azure AD)?

azure - terraform application_security_group_ids 无效或未知 key

azure - 无法在 terraform cosmosdb 中指定备份

azure-active-directory - 获取有关特定 Azure 目录的用户 Graph Explorer

terraform - 是否可以在代码块中而不是在 Web 界面中更改 Terraform Cloud 工作区执行模式?

mongodb - 是否可以在cosmos mongodb中的多重嵌套字段上创建索引?

java - 云环境中的异步任务

Azure 数据仓库数据库存储

azure - 需要在SharePoint Api组中找到Sites.FullControl.All的id