Terraform: how to read list of maps?

Multi tool use


Terraform: how to read list of maps?
See the example below:
data "aws_kms_secrets" "api_key" {
count = "${length(keys(var.keys))}"
secret {
name = "secret_name"
payload = "${element(values(var.keys), count.index)}"
}
}
resource "aws_api_gateway_api_key" "access_key" {
count = "${length(keys(var.keys))}"
name = "${var.environment}-${element(keys(var.keys), count.index)}"
value = "${lookup(element(data.aws_kms_secrets.api_key.*.plaintext, count.index), "secret_name")}"
}
It appears to be impossible to look up the plaintext values from the data resource.
value = "${lookup(element(data.aws_kms_secrets.api_key.*.plaintext, count.index), "secret_name")}"
value = "${lookup(element(data.aws_kms_secrets.api_key.*.plaintext, count.index), "secret_name")}"
Results in lookup: argument 1 should be type map, got type string in:
lookup: argument 1 should be type map, got type string in:
I have tried many combinations of element
,lookup
,*
, and dictionary syntax nothing works.
element
lookup
*
my var.keys
looks like:
var.keys
keys = {
key-name-one = "sssss"
key-name-two = "sss"
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.