【问题标题】:Terraform - azurerm_frontdoor_custom_https_configuration - 'the given key does not identify an element in this collection value'Terraform - azurerm_frontdoor_custom_https_configuration - '给定的键未标识此集合值中的元素'
【发布时间】:2022-07-12 18:07:41
【问题描述】:
  • 这段代码以前有效,我要做的只是添加新的前端端点、路由规则、后端池
  • 我已尝试仅分享我认为相关的代码 sn-ps,但如果您需要遗漏一些关键信息,请告诉我

这个问题困扰了我几天,无论我尝试了什么,我似乎都无法理解这个错误。就像它从变量中索引或搜索不存在但已经存在类似 6 的东西,现在我正在添加另一个。

我担心这个前门代码已经有一段时间没有运行了,并且有些地方搞砸了。特别是考虑到该资源随附的 TF 文档中的所有警报 - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/frontdoor_custom_https_configuration

已经有一段时间了,但 AzureRM 版本经历了几次更新 - 可能从之前的 2.58 到现在的 2.58。我想我也不知道如何验证/查看状态文件并确保其正确 - 即使查看 2.58 升级说明它只是令人困惑。

想法?

错误

on ..\modules\frontdoor\main.tf line 129, in resource "azurerm_frontdoor_custom_https_configuration" "https_config":
 129:   frontend_endpoint_id              = azurerm_frontdoor.main.frontend_endpoints[each.value]
    |----------------
    | azurerm_frontdoor.main.frontend_endpoints is map of string with 8 elements
    | each.value is "www-sell-dev-contoso-com"

The given key does not identify an element in this collection value.

ma​​in.tf

provider "azurerm" {
  features {}
}
terraform {
  backend "azurerm" {
  }
}

#the outputs.tf on this module output things like the frontdoor_endpoints
#the outputs.tf with main.tf also output similar values

module "coreInfraFrontDoor" {
  source                                       = "../modules/frontdoor"
  resource_group_name                          = module.coreInfraResourceGroup.resource_group_name
  frontdoor_name                               = "fd-infra-${terraform.workspace}-001"
  enforce_backend_pools_certificate_name_check = lookup(var.enforce_backend_pools_certificate_name_check, terraform.workspace)
  log_analytics_workspace_id                   = module.coreInfraLogAnalytics.log_analytics_workspace_id
  tags                                         = local.common_tags
  health_probes                                = lookup(var.health_probes, terraform.workspace)
  routing_rules                                = lookup(var.routing_rules, terraform.workspace)
  backend_pools                                = lookup(var.backend_pools, terraform.workspace)
  frontend_endpoints                           = lookup(var.frontend_endpoints, terraform.workspace)
  prestage_frontend_endpoints                  = lookup(var.prestage_frontend_endpoints, terraform.workspace)
  frontdoor_firewall_policy_name               = "fdfwp${terraform.workspace}001"
  frontdoor_firewall_prestage_policy_name      = "fdfwp${terraform.workspace}prestage"
  mode                                         = lookup(var.mode, terraform.workspace)
  ip_whitelist_enable                          = lookup(var.ip_whitelist_enable, terraform.workspace)
  ip_whitelist                                 = lookup(var.ip_whitelist, terraform.workspace)
  key_vault_id                                 = module.coreInfraKeyVault.id
}

模块 main.tf

resource "azurerm_frontdoor" "main" {
  name                                         = var.frontdoor_name
  location                                     = "global"
  resource_group_name                          = var.resource_group_name
  enforce_backend_pools_certificate_name_check = var.enforce_backend_pools_certificate_name_check
  tags                                         = var.tags

dynamic "routing_rule {#stuff is here obv}
dynamic "backend_pool {#also here}

#i think this is because there was an issue/needs to be some default value for the first endpoint?
frontend_endpoint {
    name                                    = var.frontdoor_name
    host_name                               = "${var.frontdoor_name}.azurefd.net"
    web_application_firewall_policy_link_id = azurerm_frontdoor_firewall_policy.main.id
  }

#now the dynamic ones from vars
dynamic "frontend_endpoint" {
    for_each = var.frontend_endpoints
    content {
      name                                    = frontend_endpoint.value.name
      host_name                               = frontend_endpoint.value.host_name
      session_affinity_enabled                = lookup(frontend_endpoint.value, "session_affinity_enabled", false)
      web_application_firewall_policy_link_id = azurerm_frontdoor_firewall_policy.main.id
    }
  }

versions.tf

terraform {
  required_version = "~> 0.14.7"
  required_providers {
    azurerm = "~>2.72.0"
  }
}

variables.tf

variable "frontend_endpoints" {
  type        = map(any)
  description = "List of frontend (custom) endpoints. This is in addition to the <frontend_name>.azurefd.net endpoint that this module creates by default."

  default = {
    dev = [
      {
        name         = "dev-search-contoso-com"
        host_name    = "dev.search.contoso.com"
      },
      {
        name         = "dev-cool-contoso-com"
        host_name    = "dev.cool.contoso.com"
      },
      ########################
      #this is new below
      ########################
      {
        name         = "dev-sell-contoso-com"
        host_name    = "dev.sell.contoso.com"
      }
   ]
   prod = [ #you get the idea ]
  }

【问题讨论】:

    标签: terraform azure-rm azure-front-door terraform-state


    【解决方案1】:

    您好,我也发现了这个错误,

    分辨率你可以在那里找到: https://discuss.hashicorp.com/t/azure-frontdoor-custom-https/31451

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 2021-05-15
      • 2021-08-20
      • 2021-08-25
      • 2021-08-26
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多