mercredi 21 juin 2023

parse json in terraform

 https://www.reddit.com/r/Terraform/comments/c07dgc/using_external_jsons_as_data_source/

    data "http" "example" {
  url = "..."
}

locals {
  example_response = jsondecode(data.http.example.body)
}
From there you can manipulate that data structure as you need. If you want to produce a map of lists then probably your next step would be to use two nested for expressions. I’m just guessing what you want the values in those lists to look like, but here’s a starting point:
    locals {
  example_rules = {
    for k, m in local.example_response : k => [
      for k, v in m : {
        key   = k
        value = v
      }
    ]
  }
}

Aucun commentaire:

Enregistrer un commentaire