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

Parsing error tfvars to json #90

Open
iamshinto opened this issue Feb 21, 2022 · 0 comments
Open

Parsing error tfvars to json #90

iamshinto opened this issue Feb 21, 2022 · 0 comments

Comments

@iamshinto
Copy link

Parsing error: tfvars to json:

terraform.tfvars:

ping_sg_cidr = {
  1 = {
    cidr_blocks = [
      "0.0.0.0/0"
    ]
    from_port   = 8
    to_port     = -1
    description = "Allow ping connections"
    protocol    = "icmp"
    self        = false
  }
}

Current output:

{
  "ping_sg_cidr": {
    "1": {
      "cidr_blocks": [
        "0.0.0.0/0"
      ],
      "from_port": 8,
      "to_port": "${-1}",
      "description": "Allow ping connections",
      "protocol": "icmp",
      "self": false
    }
  }
}

Expected output:

{
  "ping_sg_cidr": {
    "1": {
      "cidr_blocks": [
        "0.0.0.0/0"
      ],
      "from_port": 8,
      "to_port": -1,
      "description": "Allow ping connections",
      "protocol": "icmp",
      "self": false
    }
  }
}

Python code:

import hcl2, json
with open('terraform.tfvars') as f:
    print(json.dumps(hcl2.load(f), indent=2))
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