Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transforming a .tf file into .tf.json returns wrong types #179

Open
rami-foo opened this issue Dec 17, 2024 · 0 comments
Open

Transforming a .tf file into .tf.json returns wrong types #179

rami-foo opened this issue Dec 17, 2024 · 0 comments

Comments

@rami-foo
Copy link

rami-foo commented Dec 17, 2024

Here's a minimal reproduction code to show what i mean

variables.tf

variable "create_main_node_group" {
  description = "Create main node group, main-node-group.tf"
  type        = bool
  default     = true
}

test.py

import json
from pathlib import Path
import hcl2

file_path = Path("./variables_override.tf").resolve()
with open(file_path) as fp:
    json_object = hcl2.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": [
        {
            "create_main_node_group": {
                "description": "Create main node group, main-node-group.tf",
                "type": "bool",
                "default": true
            }
        }]
}

actual output

{
    "variable": [
        {
            "create_main_node_group": {
                "description": "Create main node group, main-node-group.tf",
                "type": "${bool}",
                "default": true
            }
        }]
}

This breaks all terraform commands from working as it doesn't understand the new type:
terraform init

 Error: Invalid type specification

   on variables_override.tf.json line 6, in variable[0].create_main_node_group:
    6:                 "type": "${bool}",

A type specification is either a primitive type keyword (bool, number,
 string) or a complex type constructor call, like list(string).

There is also the issue that the variables is a list and all in all the transformation doesn't seem to work with this library which is a shame but this main issue is still a problem nontheless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant