I am trying to parse JSON key/value pairs into a map I can use in Terraform during a lookup.
I've created a null_resource with a local-exec provisioner to run my aws cli command and then parsed with jq to clean it up. The JSON looks good, the correct key/value pairs are displayed when run from the CLI. I created an external data block to convert the JSON into an TF map, but I'm getting an Inccorect attribute error from TF.
resource "null_resource" "windows_vars" {
provisioner "local-exec" {
command = "aws ssm --region ${var.region} --profile ${var.profile} get-parameters-by-path --recursive --path ${var.path} --with-decryption | jq '.Parameters | map({'key': .Name, 'value': .Value}) | from_entries'"
}
}
data "external" "json" {
depends_on = [null_resource.windows_vars]
program = ["echo", "${null_resource.windows_vars}"]
}
output "map" {
value = ["${values(data.external.json.result)}"]
}
I expected the key/value pairs to be added to a TF map I could use elsewhere. I got the following error:
Error: Incorrect attribute value type
on instances/variables.tf line 33, in data "external" "json":
33: program = ["echo", "${null_resource.windows_vars}"]
Inappropriate value for attribute "program": element 1: string required.
JSON output looks like this:
{
"/vars/windows/KEY_1": "VALUE_1",
"/vars/windows/KEY_2": "VALUE_2",
"/vars/windows/KEY_3": "VALUE_3",
"/vars/windows/KEY_4": "VALUE_4"
}
null_resource
– BMW