json.Marshal(): json: 为 msgraph.Application 类型调用 MarshalJSON 时出错 [英] json.Marshal(): json: error calling MarshalJSON for type msgraph.Application

查看:19
本文介绍了json.Marshal(): json: 为 msgraph.Application 类型调用 MarshalJSON 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What specific syntax or configuration changes must be made in order to resolve the error below in which terraform is failing to create an instance of azuread_application?

代码:

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

The terraform code that is triggering the error when terraform apply is run is as follows:

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 运行上述代码产生的错误和日志输出是:

The error and log output that result from running the above code with terraform apply are:

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 ........modulesad-adminactive-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 给出:

地形 v1.0.8在 windows_amd64 上

Terraform v1.0.8 on windows_amd64

推荐答案

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

This was a bug, reported as GitHub issue:

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

The resolution to the problem in the OP is to upgrade the version from 2.5.0 to 2.6.0 in the required_providers block from the code in the OP above as follows:

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

这篇关于json.Marshal(): json: 为 msgraph.Application 类型调用 MarshalJSON 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆