Terragrunt: Yamldecode decodes all variables into string type

Created on 14 Jul 2020  ยท  2Comments  ยท  Source: gruntwork-io/terragrunt

I'd like to use yaml formatted variables for terraform with terragrunt. But variables passed to terraform are all with string type, but source vars are all have different types.

Current working tree

.
โ”œโ”€โ”€ dns
โ”‚ย ย  โ””โ”€โ”€ terragrunt.hcl
โ”œโ”€โ”€ dns-records.yaml
โ”œโ”€โ”€ terragrunt.hcl
โ””โ”€โ”€ variables.yaml

dns-records.yaml contents

dns_zones:
  - name: "test-com"
    dns_name: "test.com."

dns_records:
  test-com:
    - name: "anothertest"
      type: "CNAME"
      rrdatas: ["test.com."]

variables.yaml contents

#Test variable
test: "supertest"

Parent terragrunt.hcl

inputs = yamldecode(file("variables.yaml"))

Terragrunt.hcl in dns folder

include {
  path = find_in_parent_folders()
}
terraform {
  source = "/home/bankinobi/work/terraform-modules/dns"
}

inputs = yamldecode(file("${find_in_parent_folders("dns-records.yaml")}"))

Here is my tfstate after refreshing outputs in source module:

{
  "version": 4,
  "terraform_version": "0.12.28",
  "serial": 9,
  "lineage": "4d9e1f5d-aa1f-1d6f-2eba-173f2f91f4ef",
  "outputs": {
    "records": {
      "value": "{\"test-com\":[{\"name\":\"anothertest\",\"rrdatas\":[\"test.com.\"],\"type\":\"CNAME\"}]}",
      "type": "string"
    },
    "test": {
      "value": "supertest",
      "type": "string"
    },
    "zones": {
      "value": "[{\"dns_name\":\"test.com.\",\"name\":\"test-com\"}]",
      "type": "string"
    }
  },
  "resources": []
}

How can i decode yamls with preserving variables types?

question

All 2 comments

This is the same issue as https://github.com/gruntwork-io/terragrunt/issues/1007, https://github.com/gruntwork-io/terragrunt/issues/997, and https://github.com/gruntwork-io/terragrunt/issues/1002. You need to add the type information to the variables in terraform to get it to decode properly.

Thank you so much for your help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GauntletWizard picture GauntletWizard  ยท  3Comments

zachwhaley picture zachwhaley  ยท  3Comments

antonbabenko picture antonbabenko  ยท  3Comments

jtai-omniex picture jtai-omniex  ยท  3Comments

dmlemos picture dmlemos  ยท  3Comments