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

json2hcl is json-esq not HCL standard #4

Closed
Daviey opened this issue Jan 26, 2017 · 1 comment
Closed

json2hcl is json-esq not HCL standard #4

Daviey opened this issue Jan 26, 2017 · 1 comment

Comments

@Daviey
Copy link

Daviey commented Jan 26, 2017

An original tf file is like this:

resource "aws_instance" "XXX" {
  ami                         = "ami-XXXX"
  availability_zone           = "us-east-1b"
  ebs_optimized               = false
  instance_type               = "t2.micro"
  monitoring                  = false
  key_name                    = ""
  subnet_id                   = "subnet-XXXX"
  vpc_security_group_ids      = ["sg-XXX"]
  associate_public_ip_address = false
  private_ip                  = "XXXX"
  source_dest_check           = true

  root_block_device {
    volume_type           = "gp2"
    volume_size           = 8
    delete_on_termination = false
  }

  ebs_block_device {
    device_name           = "/dev/sde"
    snapshot_id           = "snap-XXXXXX"
    volume_type           = "gp2"
    volume_size           = 100
    delete_on_termination = false
  }

  tags {
    "Name" = "XXXX"
  }
}

I would expect this operation to be identical.. but it mangles it (white space as copied)

$ json2hcl --reverse < file.tf | json2hcl

"resource" = {
  "aws_instance" = {
    "" = {
      "ami" = "ami-89272XXX"

      "associate_public_ip_address" = "false"

      "availability_zone" = "us-east-1b"

      "ebs_optimized" = "false"

      "instance_type" = "t2.micro"

      "key_name" = "XXX"

      "monitoring" = "false"

      "private_ip" = "XXX"

      "root_block_device" = {
        "delete_on_termination" = "false"

        "volume_size" = 8

        "volume_type" = "gp2"
      }

      "source_dest_check" = "true"

      "subnet_id" = "subnet-XXXXX"

      "tags" = {
        "Name" = ""
      }

      "vpc_security_group_ids" = ["sg-XXXXX"]
    }
  }
}

@Acconut
Copy link
Collaborator

Acconut commented Jan 26, 2017

Sadly, this behavior is caused by Hasicorp's official HCL library due to ambiguities in the HCL format. Therefore, we are not really able to improve this situation. We had similar discussions in the past, if you may want to read more on this topic and why this will probably not be changed in the future:

#3 and
hashicorp/hcl#162

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

3 participants