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")}"
Results 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.
my var.keys
looks like:
keys = {
key-name-one = "sssss"
key-name-two = "sss"
}
The trick here is to use the dictionary syntax to replace the element call, it behaves better with lists of maps.
value = "${lookup(data.aws_kms_secrets.api_key.*.plaintext[count.index], "secret_name")}"
its tempting to do data.aws_kms_secrets.api_key[count.index].plaintext
that isn't valid HCL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With