Hello, I’ve a problem with archive_file
data source.
I’ve a condition which is creates a lambda layer:
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
---
Other code
---
}
resource "aws_lambda_layer_version" "layers"
working as expected, and creates a lambda layer, if filename
and source_code_hash
are defined as shown above (Without using data source
).
And I have a
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)
---
Other code
---
}
As you can see, the for_each
block are same with resource block, but I’v got an error:
each.value is object with 2 attributes
Finally here is my module block, where I call this resources
---
layers = [
{
name = "test-layer"
runtimes = [ "nodejs12.x" ]
# * Archive Configuration(s)
archive = {
type = "zip"
---
Other code
---
}
}
]
---
So my question is, why same for_each
block working differently?