簡體   English   中英

給定鍵未標識此集合值中的元素,用於 Azure 存儲帳戶 primary_access_key 輸出值

[英]The given key does not identify an element in this collection value for azure storage account primary_access_key output value

我正在嘗試從 foreach 的存儲帳戶中提取 primary_access_key 值並分配給函數應用程序。 但是我無法獲得 primary_access_key 值,因為它不是 foreach 集合的一部分。

變量.tf

variable "stack_version"{
type = string
}
variable "functionappname"
{
type = string
}
variable "storage_list" {
    type = list
}
variable "rg" {
      type        = string
}
variable "loc" {
     type        = string
}

變量.tfvars

resourcegroupname = "test-rg"
location          = "eastus"
storage_list  = ["mystorageaccount"]
functionappname = "myfunctionapp"
stack_version   = { node = "~14" }

存儲帳戶模塊

resource "azurerm_storage_account" "storageaccount" {
  for_each = toset(var.storage_list) 
  name=each.value
  resource_group_name = var.rg
  location = var.loc
  account_tier = "Standard"
  account_replication_type = "GRS"
}

輸出.tf

output "sa_primary_access_key_out"{
    value = { for storageaccount in azurerm_storage_account.storageaccount : storageaccount.name =>  storageaccount.primary_access_key }
    sensitive = true   
}

output "sa_name_out"{
    value = { for storageaccount in azurerm_storage_account.storageaccount : storageaccount.name =>  storageaccount.name }
}

當我嘗試為 Function 應用程序使用存儲帳戶模塊輸出時,出現以下錯誤。

module "FUNAPP_StorageAccount" {
  source            = "../../modules/StorageAccount"
  storage_list      = var.storage_list
  resourcegroupname = module.ResourceGroup.rg_name_out
  location          = var.loc
}
module "FunctionApp" {
  depends_on = [
    module.ResourceGroup,
    module.StorageAccount
  ]
  source                            = "../../modules/FunctionApp"
  resourcegroupname                 = module.ResourceGroup.rg_name_out
  location                          = var.loc
  service_plan_id                   = data.azurerm_service_plan.shared-appservice-plan.id
  storageaccountname                = module.FUNAPP_StorageAccount.sa_name_out["mystorageaccount"]
  storage_account_access_key        = module.FUNAPP_StorageAccount.sa_primary_access_key_out["sa_primary_access_key_out"]
  functionappname                   = var.functionappname
  stack_version                     = var.stack_version                     
}

錯誤:

│ Error: Invalid index
│ 
│   on main.tf line 45, in module "FunctionApp":
│   45:   storage_account_access_key        = module.FUNAPP_StorageAccount.sa_primary_access_key_out["primary_access_key"]
│     ├────────────────
│     │ module.FUNAPP_StorageAccount.sa_primary_access_key_out has a sensitive value
│ 
│ The given key does not identify an element in this collection value.

您在定義的代碼中沒有任何名為sa_primary_access_key_out的密鑰。 相反,您以這種方式進行輸出調用。 它應該是:

storage_account_access_key        = module.FUNAPP_StorageAccount.sa_primary_access_key_out["mystorageaccount"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM