Decoding JSON string to terraform map

data "external" "json" {
  program = ["echo", "${var.json}"]
}

output "map" {
  value = "${data.external.json.result}"
}

Since 0.12 version of the Terraform you can use jsondecode function to decode json into a Terraform map. More details on: https://www.terraform.io/docs/configuration/functions/jsondecode.html

example from the page above:

> jsondecode("{\"hello\": \"world\"}")
{
  "hello" = "world"
}
> jsondecode("true")
true

Tags:

Terraform