簡體   English   中英

Terrafrom。 數據、archive_file 錯誤或錯誤?

[英]Terrafrom. Data, archive_file error or bug?

我對archive_file數據源有疑問。 我有一個條件是創建一個 lambda 層:

resource "aws_lambda_layer_version" "layers" {
   for_each = { for layers, name in local.lambdas.options.layers : layers => name if local.lambdas.init.self && local.lambdas.extras.layers }
   filename = "not_working" #data.archive_file.layers[each.key].output_path
   source_code_hash = "not_working" #data.archive_file.layers[each.key].output_base64sha256
   
   ...
}

資源"aws_lambda_layer_version" "layers"按預期工作,並創建一個 lambda 層,如果filenamesource_code_hash如上所示定義(不使用數據源)。

我有一個

data "archive_file"  "layers"  {
   for_each = { for layers, name in local.lambdas.options.layers : layers => name if local.lambdas.init.self && local.lambdas.extras.layers }
   type = lookup(each.value.archive, "type", null)
   
   ...
}

如您所見, for_each塊與資源塊相同,但出現錯誤:

each.value is object with 2 attributes

最后這是我的模塊塊,我稱之為資源

layers  = [
   {
      name        = "test-layer"
      runtimes    = [ "nodejs12.x" ]
      archive     = {
         type        = "zip"
      
         ...
      }
   }
]

所以我的問題是,為什么相同的for_each塊工作方式不同?

我已經復制了你的代碼,對我來說它正在工作;

resource "null_resource" "cmd" {
   for_each        = { for lambda, name in local.lambdas.init.mods : lambda => name if local.lambdas.init.self && local.lambdas.trigger.laps }
   provisioner "local-exec" {
       command     = lookup(each.value.archive, "command", null)
       working_dir = lookup(each.value.archive, "modules", null)
   }
}
data "archive_file"  "layers"  {
   for_each        = { for lambda, name in local.lambdas.init.mods : lambda => name if local.lambdas.init.self && local.lambdas.trigger.laps }
   depends_on      = [ null_resource.cmd ]
   type            = lookup(each.value.archive,    "type",    null)
   source_dir      = lookup(each.value.archive,    "modules", null)
   output_path     = "${lookup(each.value.archive, "outputs", null)}/${lookup(each.value, "function", null)}.${lookup(each.value.archive, "type", null)}"
   output_file_mode  = lookup(each.value.archive,  "mode",    null)
}

暫無
暫無

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

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