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 of maps in JSON variable files is broken. #15549

Closed
dbeckham opened this issue Jul 13, 2017 · 5 comments
Closed

Parsing of maps in JSON variable files is broken. #15549

dbeckham opened this issue Jul 13, 2017 · 5 comments
Milestone

Comments

@dbeckham
Copy link

When declaring a map in JSON format in a Terraform variable file, it produces the error:

invalid value "myfile.tfvars" for flag -var-file: multiple map declarations not supported for variables

This looks to be a specific issue for the JSON format. Maps appear to work correctly for the HCL format, but is broken when using JSON.

Terraform Version

Terraform 0.9.11

Terraform Configuration Files

main.tf

variable "test_map" {
    type = "map"
}

hcl.tfvars

test_map = {
    "key1" = {
        "index1" = "data2"
        "index2" = "data2"
    }
    "key2" = {
        "index1" = "data1"
    }
}

json.tfvars

{ "test_map": { "key1": {"index1": "data1", "index2": "data2"}, "key2": {"index1": "data1"} } }

Debug Output

https://gist.github.com/dbeckham/6a85d7c0fdbaed19521ff59ffb12b387

Expected Behavior

The JSON format should be treated exactly the same as HCL, and both test HCL and JSON test files should be treated the same.

Actual Behavior

Terraform produced the error:

invalid value "myfile.tfvars" for flag -var-file: multiple map declarations not supported for variables

Steps to Reproduce

Take the three files above and run the following commands:

If you run Terraform using the HCL file agove, you get the normal output telling you:

$ terraform plan -var-file=hcl.tfvars
No changes. Infrastructure is up-to-date.

If you run the same command using the JSON version, you get the error:

$ terraform plan -var-file=json.tfvars
invalid value "json.tfvars" for flag -var-file: multiple map declarations not supported for variables
@jantman
Copy link

jantman commented Sep 28, 2017

As far as I can tell this is a more widespread bug regarding maps in JSON files. While the documentation claims that JSON and HCL are interchangeable, as far as maps are concerned, this appears to not be the case.

My use case is managing Amazon ECR (docker image for ECS) repositories. You need to define an ECR Repository for every image, so this becomes really cumbersome to maintain manually... so I'm trying to generate the terraform config from an external datasource.

I'm seeing this same bug, but with a map in an output in a .tf.json file.

infra_ecr.tf.json:

{
  "resource": {
    "aws_ecr_repository": {
      "jantman_private-docker-redirector": {
        "name": "jantman/private-docker-redirector"
      }
    }
  },
  "output": {
    "ecr_jantman_private-docker-redirector": {
      "value": {
        "arn": "${aws_ecr_repository.jantman_private-docker-redirector.arn}",
        "name": "${aws_ecr_repository.jantman_private-docker-redirector.name}",
        "registry_id": "${aws_ecr_repository.jantman_private-docker-redirector.registry_id}",
        "url": "${aws_ecr_repository.jantman_private-docker-redirector.url}"
      }
    }
  }
}

fails with:

* ecr_jantman_private-docker-redirector: output has invalid keys: registry_id, url, arn, name
* ecr_jantman_private-docker-redirector: output is missing required 'value' key

But infra_ecr.tf:

resource "aws_ecr_repository" "jantman_private-docker-redirector" {
  name = "jantman/private-docker-redirector"
}

output "ecr_jantman_private-docker-redirector" {
  value = {
    "arn" = "${aws_ecr_repository.jantman_private-docker-redirector.arn}",
    "name" = "${aws_ecr_repository.jantman_private-docker-redirector.name}",
    "registry_id" = "${aws_ecr_repository.jantman_private-docker-redirector.registry_id}",
    "url" = "${aws_ecr_repository.jantman_private-docker-redirector.url}"
  }
}

works fine.

@mikedmcfarland
Copy link

I understand that this is an open bug, however may I suggest at least updating these docs? The following statement is particularly misleading
The downsides of JSON are less human readability and the lack of comments. Otherwise, the two are completely interoperable.
lost some time writing some codgen, assumed that statement was accurate.

@apparentlymart
Copy link
Member

Hi all! Sorry for the weird behavior and the long silence here.

This seems to be the same as #9555, which I closed today after verifying that it is fixed in Terraform v0.12.0-alpha1. I posted some more details in a comment in the other issue. The fix will also be included in the final v0.12.0 release. Thanks for reporting the issue, and sorry again for the slow response.

@apparentlymart apparentlymart modified the milestone: v0.12.0 Oct 29, 2018
@dzabel
Copy link

dzabel commented Feb 26, 2019

as pointed out here: #9239 (comment)

test_map in json has to be defined:

{"test_map": [{
   "key1": [{
     "index1": "data1", 
     "index2": "data2",
   }],
   "key2": [{
     "index1": "data1",
   }],
 }]}

for my use case this wokrs like a charm.

yrobla pushed a commit to yrobla/kni-installer that referenced this issue Apr 16, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
yrobla pushed a commit to yrobla/kni-installer that referenced this issue Apr 16, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
yrobla pushed a commit to yrobla/kni-installer that referenced this issue Apr 16, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
yrobla pushed a commit to yrobla/kni-installer that referenced this issue Apr 16, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
yrobla pushed a commit to yrobla/kni-installer that referenced this issue Apr 16, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
yrobla pushed a commit to yrobla/kni-installer that referenced this issue Apr 17, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
yrobla pushed a commit to yrobla/kni-installer that referenced this issue Apr 17, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
yrobla pushed a commit to yrobla/kni-installer that referenced this issue Apr 18, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to openshift-metal3/kni-installer that referenced this issue May 8, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue May 9, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue May 13, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue May 20, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to openshift-metal3/kni-installer that referenced this issue May 29, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue May 29, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue Jun 3, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue Jun 18, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue Jun 19, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue Jun 21, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue Jul 1, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
stbenjam pushed a commit to stbenjam/kni-installer that referenced this issue Jul 3, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
markmc pushed a commit to markmc/kni-installer that referenced this issue Jul 8, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
markmc pushed a commit to openshift-metal3/kni-installer that referenced this issue Jul 8, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
hardys pushed a commit to hardys/kni-installer that referenced this issue Jul 12, 2019
Change the data structure to accept data of nodes using maps.
This will allow to add a variable number of masters (1,3) in the future.
Added a new dependency on rodaine/hclencoder, to render terraform data
in HCL instead of JSON, to avoid a bug in JSON parsing:
hashicorp/terraform#15549
@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants