Skip to content

Error converting .tf into .tf.json when there is a variable with a non primitive type #92

@Rami-Kassouf-FOO

Description

@Rami-Kassouf-FOO

Basically this is a minimal reconstruction of the issue

variables.tf:

variable "efs_tags" {
  description = "Tags for the EFS"
  type        = map(string)
  default = {
    Terraform = "true"
    Project   = "" 
  }
}

python code

import json
from pathlib import Path
import hcl

file_path = Path("./variables.tf")
with open(file_path) as fp:
    json_object = hcl.load(fp)

file_path = file_path.with_suffix('.tf.json')
with open(file_path, 'w') as fp:
    json.dump(json_object, fp, indent=4)

expected output:

{
    "variable": {
         "efs_tags": {
                  "description": "Tags for the EFSr",
                  "type": "map(string)",
                  "default": {
                          "Terraform": "true",
                          "Project": ""
                  }
        }
}

Actual output:

{
    "variable": {
         "efs_tags": {
                  "description": "Tags for the EFSr",
                  "type": "map(\"string\")",
                  "default": {
                          "Terraform": "true",
                          "Project": ""
                  }
        }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions