Microsoft.Web/certificates@2021-02-01 的 Terraform azapi_resource 不再工作

问题描述 投票:0回答:1

我正在使用 Terraform 1.8.0。

我正在尝试创建 Azure 托管证书。基于证书。保存在 Azure Key-Vault 中(作为秘密存储)。

Terraform 本地文件...

az_managed_ssl_cert_name = "ssl-wildcard-ds-UK-ABC-certabcdefghijkl"

Terraform main.tf...

    # ASP for Re-Id Function-Apps
module "app_service_plan_03" {
  source               = "../../resource_modules/app_service_plan"
  os_type              = var.os_type_fapps_re_id
  sku_name             = var.sku_name_fapps_re_id
  location             = var.location
  rg                   = local.re_id_rg_name
  name                 = local.app_service_plan_03
  max_worker_count     = var.max_app_service_plan_01_worker_count_re_id
  min_worker_count     = var.min_app_service_plan_01_worker_count_re_id
  law_id               = data.azurerm_log_analytics_workspace.law.id
  enable_resource_lock = var.re_id_enable_asp_resource_lock
}



resource "azapi_resource" "cert" {
          depends_on = [data.azurerm_subscription.current]
          type       = "Microsoft.Web/certificates@2021-02-01"
          name       = var.cert_name
          parent_id  = local.certificate_resource_group # Resource Group name where certificate is created.
    
      body = jsonencode({
        "location" : var.location,
        "properties" : {
          "serverFarmId" : data.azurerm_service_plan.asp.id,
          "keyVaultId" : data.azurerm_key_vault.kv_certs.id, # The Azure Key vault that stores the SSL certificates is in the 'Production' subscription.
          "keyVaultSecretName" : local.az_managed_ssl_cert_name
        }
      })
    }

当我构建 Terraform 时,它报告错误。然后我将代码剥离回原来的状态...

    resource "azapi_resource" "cert" {
  depends_on = [data.azurerm_subscription.current, module.app_service_plan_03, data.azurerm_key_vault.kv_certs]
  type       = "Microsoft.Web/certificates@2021-02-01"
  name       = local.cert_name
  parent_id  = module.create_resource_group.id

  body = jsonencode({
    "location" : var.location,
    "properties" : {
      "keyVaultSecretName" : "abcdef"
    }
  })
}

报告的错误与主体有关...

    │ Error: Invalid body
    │ 
    │   with azapi_resource.cert,
    │   on main.tf line 206, in resource "azapi_resource" "cert":
    │  206: resource "azapi_resource" "cert" {
    │ 
    │ The argument "body" is invalid: unmarshaling failed: value:
    │ "{\"location\":\"uksouth\",\"properties\":{\"keyVaultSecretName\":\"abcdef\"}}",
    │ err: json: cannot unmarshal string into Go value of type
    │ map[string]interface {}
    ╵
    ╷
    │ Error: Invalid Type
    │ 
    │   with azapi_resource.cert,
    │   on main.tf line 212, in resource "azapi_resource" "cert":
    │  212:   body = jsonencode({
    │  213:     "location" : var.location,
    │  214:     "properties" : {
    │  215:       "keyVaultSecretName" : "abcdef"
    │  216:     }
    │  217:   })

│ 
│ The value must not be a string

我不明白我哪里出了问题 - 有任何建议吗?

azure terraform azure-rm
1个回答
0
投票

我在另一个资源上遇到了类似的错误。

最近(21-10-2024)发布了新版本的 azapi 提供程序(2.0.1),尝试将版本设置为 1.15.0

© www.soinside.com 2019 - 2024. All rights reserved.