Parsing json data using terraform to use as varibles for resources

Hi,

I am newbie in terraform. I need help to create map from json file I have.

I have json like this

[
{
“Key”: “value0”,
“key1”: [
“valueA”,
“valueB”,
“valueC”
]
},
{
“Key”: “value1”,
“key1”: [
“valueD”,
“valueE”,

  ]
},
{
  "Key": "value2",
  "key1": []
},

]

I want like this in map so that i can consume them in terramform resources.

variable “name”{

default = {

value0 = valueA
value0 = valueB
value0 = valueC
value1 = valueD
Value1 = valueF

}
}

Hi,

You can try to use next code sample:

locals {

    settings = [

        {

            Key = "value0",

            key1 = [

                "valueA",

                "valueB",

                "valueC"

            ]

        },

        {

            Key = "value1",

            key1 = [

                "valueD",

                "valueE",    

            ]

        },

        {

            Key = "value2",

            key1 = []

        }

    ]

}

Hi,

Thank you for your reply.

The problem is the json file is dynamic and I do not know the values of key and values inside json.

I need to do parse of json to find key and value and use them in my terraform resources.

Hope i am clear.

Thank you.

Hi,

I just thought to clarify once again that I want to generate map form JSON file that I have given.

So that I can use all the variables including key and values from JSON , I am not sure if a loop can itterate directly from JSON.

Thank you