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

Empty arrays interpreted as unset variable when reading from .tf.json formatted variable files #8886

Closed
Fitzsimmons opened this issue Sep 16, 2016 · 2 comments

Comments

@Fitzsimmons
Copy link

It seems empty arrays defined in .tf.json files are not interpreted as set variables. I was able to reduce this problem to a very small test case on Terraform v0.7.3.

provision.tf

variable "foo" {
    type = "list"
}

provider "aws" {
    region = "us-east-1"
}

resource "aws_vpc" "vpcs" {
    count = "${length(var.foo)}"
    cidr_block = "${element(var.foo, count.index)}"
}

After terraform planing with an empty variable in an hcl-style config, the plan comes out as empty as expected:

tfvars/variables.tfvars

foo = []
$ terraform plan -var-file=tfvars/variables.tfvars
[snip]
No changes. Infrastructure is up-to-date.
[snip]

However, if I try this with an equivalent json file, I'm prompted for input.

json/variables.tf.json

{ "foo": [] }
$ terraform plan -var-file=json/variables.tf.json
var.foo
  Enter a value: ^C
Error configuring: Error asking for foo: interrupted

This is specifically a problem with empty arrays in json, because if I populate the array with a value, terraform becomes aware that it has been set.

json/variables.tf.json

{ "foo": ["192.168.77.0/24"] }
$ terraform plan -var-file=variables.tf.json
[snip]
+ aws_vpc.vpcs
    cidr_block:                "192.168.77.0/24"
    default_network_acl_id:    "<computed>"
    etc ...

It would be great if empty arrays read from JSON files were actually interpreted as such.

@mitchellh
Copy link
Contributor

Thanks! I have a PR open for the HCL project that will fix this. Once that is merged, I'll also add a failing test for your case here in Terraform (to avoid regressions in this project) and update the HCL vendor.

mitchellh added a commit that referenced this issue Oct 25, 2016
This will be fixed when the HCL vendor is updated after mergin the PR
over there.
@ghost
Copy link

ghost commented Apr 21, 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 Apr 21, 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

3 participants