'Create a nested object in terraform
we are fetching key-value pairs from consul and we are trying to create an object of objects from the returning values. Basically, Consul returns the full path of the key, and we want to create a sub object from each recursive path.
We get this -
{
"appPort" = "3000"
"dockerAuth" = "regcred"
"failureThreshold" = "3"
"interval" = "10"
"livenessProbe/failureThreshold" = "3"
"livenessProbe/interval" = "10"
"livenessProbe/path" = "/health/isalive"
"livenessProbe/port" = "3000"
"livenessProbe/startDelay" = "60"
"livenessProbe/successThreshold" = "1"
"livenessProbe/timeout" = "10"
"path" = "/health/isalive"
"port" = "3000"
"pullPolicy" = "IfNotPresent"
"readinessProbe/failureThreshold" = "3"
"readinessProbe/interval" = "30"
"readinessProbe/path" = "/health/isready"
"readinessProbe/port" = "3000"
"readinessProbe/startDelay" = "60"
"readinessProbe/successThreshold" = "3"
"readinessProbe/timeout" = "10"
"replicaCount" = "3"
"startDelay" = "60"
"successThreshold" = "1"
"timeout" = "10"
}
And we want to create this -
{
"appPort" = "3000"
"dockerAuth" = "regcred"
"failureThreshold" = "3"
"interval" = "10"
"livenessProbe" = {
"failureThreshold" = "3"
"interval" = "10"
"path" = "/health/isalive"
"port" = "3000"
"startDelay" = "60"
"successThreshold" = "1"
"timeout" = "10"
}
"path" = "/health/isalive"
"port" = "3000"
"pullPolicy" = "IfNotPresent"
"readinessProbe"= {
"failureThreshold" = "3"
"interval" = "30"
"path" = "/health/isready"
"timeout" = "10"
"successThreshold" = "3"
"port" = "3000"
}
"replicaCount" = "3"
"startDelay" = "60"
"successThreshold" = "1"
"timeout" = "10"
}
Any Ideas? Thanks!
Solution 1:[1]
Not sure why you would do this via terraform, but if you do need it in terraform, you could either create a templatefile and render your data through that or have a null resources and format it externally ( say with a bash script ) and then re-use it in terraform.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DarkMukke |
