Skip to content

hcl.Unmarshal adding spurious arrays #162

Description

@jantman

I'm not entirely sure if this is a bug or not. However, I was using https://github.com/kvz/json2hcl in reverse mode to convert a HCL example to JSON, and stumbled on this...

HCL Template

Taken directly from https://vagrantcloud.com/help/vault/vsi/configuration

environment "aws" {
}

vault {
  address = "https://vault.service.consul:8200"
  mount_path = "auth/aws"
}

serve "file" {
  path = "/ramdisk/vault-token"
}

Expected behavior

What should have happened?

{
  "environment": {
    "aws": {}
  },
  "serve": {
    "file": {
      "path": "/ramdisk/vault-token"
    }
  },
  "vault": {
    "address": "https://vault.service.consul:8200",
    "mount_path": "auth/aws"
  }
}

Actual behavior

An invalid configuration, according to VSI:

{
  "environment": [
    {
      "aws": [
        {}
      ]
    }
  ],
  "serve": [
    {
      "file": [
        {
          "path": "/ramdisk/vault-token"
        }
      ]
    }
  ],
  "vault": [
    {
      "address": "https://vault.service.consul:8200",
      "mount_path": "auth/aws"
    }
  ]
}

This JSON has an extra level of arrays inside each top-level object, which is detected as invalid.

Steps to reproduce

I was using https://github.com/kvz/json2hcl for this, which is a CLI wrapper around hcl.

  1. Clone and build https://github.com/kvz/json2hcl
  2. Write the hcl template example to a file
  3. cat example.hcl | json2hcl -reverse

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v1Relates to the v1 line of releases

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions