In Terraform 0.7 I have observed an issue with handling numeric variables. To replicate this issue, you need to create two files, main.tf:
variable "some_number" {
type = "string"
default = 0
}
And terraform.tfvars.json:
{
"some_number": 1
}
Running terraform apply produces the following error:
Errors:
* 1 error(s) occurred:
* variable some_number should be type string, got number
I'm facing this one too, it also happens when supplying the value as a cli parameter:
-var node_count=1
-var node_count="1"
-var node_count='1'
In my vars.tf:
variable "node_count" {
description = "Number of nodes/instances to provision"
type = "string"
default = "1"
}
Also tried without type = "string".
All the above variations give me the same error:
Errors:
* 1 error(s) occurred:
* variable node_count should be type string, got number
@denisbr Seeing the same thing when supplying var on the cli. I've tried nearly every combination imaginable and haven't discovered a temporary workaround. I've reverted back v.0.6.16.
There must be a bug in whatever "magic" is performing the type validation. For my use case, I'm specifying the short version of a git sha as a terraform variable:
GIT_SHA=$(git rev-parse --short HEAD)
The result of this can contain all numbers, all letters, or a combination of letters and numbers (and also may start with either a letter or a number).
Before updating to 0.7, I did not explicitly define the variable type and did not run into any issues.
When a variable's type is explicitly defined, perhaps there should be an attempt to cast that variable to a string (numbers -> string of numbers) prior to validation?
EDIT - Pull request 7977 is open for this.
Hey folks - sorry for the trouble here! You can work around this by wrapping double quotes around the flag, but you have to make sure your shell passes them through to Terraform.
So, to use @denisbr's example, this should work:
terraform plan -var 'node_count="1"'
We'll be landing #7977 shortly and the fix will be out in v0.7.1 soon!
@phinze Thanks for giving a workaround suggestion, I'll wait for the fix to land in 0.7.1 and stay on 0.6.x for a little longer.
The same error happens with boolean vars too. The same workaround works.
Errors:
* 1 error(s) occurred:
* variable associate_public_ip_address should be type string, got boolean
Was this not supposed to be resolved in 0.7.1? as im still seeing it wen running the below code
variable "instance_ebssize" {
type = "string"
default = "20"
}
Errors:
* 1 error(s) occurred:
* variable instance_ebssize should be type string, got number
@fluzz seeing the same thing on 0.7.1. No reference to this issue in the changelog. The workaround mentioned above won't solve my specific use-case (passing bash vars to TF vars). Ultimately I switched over to loading the variables from a file (which is dynamically generated from bash prior to terraform execution).
Seeing the same thing on 0.7.2 as well. Can't seem to get the workaround to work on 0.7.2 either.
@phinze Care to enlighten us on this issue? It's still keeping me from going to 0.7.x.
@phinze #7977 did not fix the issue. I just tested the following with Terraform 0.7.2:
variable "foo" {}
Run the following at the command line:
terraform apply -var 'foo = 5'
Get error:
* variable foo should be type string, got number
Same happens for boolean too.
I am seeing the same thing with 0.7.2
Seeing the same behavior in 0.7.3
@akoeb-zalando the workaround still works though:
terraform plan -var 'node_count="1"'
Seeing this too in 0.7.2 and 0.7.3.
@phinze workaround works well:
terraform plan -var 'deploy_account="1234567890"'
Seeing this on 0.7.3 as well
Don't either @phinze or anyone at hashicorp care about this at all? Not a quick word on this? @mitchellh ?
@denisbr We do! Because this bug has a workaround, we prioritize bugs that don't have workarounds first since they're obvious blockers.
But this bug is tagged and we handle core bugs as quickly as possible. If you want to see it done quicker I encourage a pull request according to our contribution guide which is detailed. If that is followed (helpful checkboxes guide you the way) then we can merge very, very quickly.
I promise we'll get to it. :)
Just as a reminder to all, the recommended workaround doesn't help when you're passing through bash variables. For this use case, you'll need to create a variable file and load them that way.
Ok, thanks. Just a very long thread without any word from hashicorp. I'm
relieved now.
On Fri, 16 Sep 2016 at 16:50, Mitchell Hashimoto [email protected]
wrote:
@denisbr https://github.com/denisbr We do! Because this bug has a
workaround, we prioritize bugs that don't have workarounds first since
they're obvious blockers.But this bug is tagged and we handle core bugs as quickly as possible. If
you want to see it done quicker I encourage a pull request according to our contribution
guide
https://github.com/hashicorp/terraform/blob/master/.github/CONTRIBUTING.md
which is detailed. If that is followed (helpful checkboxes guide you the
way) then we can merge very, very quickly.I promise we'll get to it. :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/hashicorp/terraform/issues/7962#issuecomment-247620649,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAdORvlE4YoY97PHDY3UF3j8DwtNPx2Mks5qqqy7gaJpZM4JcNbA
.
Denis Brækhus Senior Engineer | Varnish Software AS
Cell: +47 48047724
We Make Websites Fly!
www.varnish-software.com
New to terraform here.
How would I do this workaround with a file on ubuntu (using bash)?
The doc does not describe how to use "number".
Also hitting this bug after upgrading to 0.7 but we're using var-file and so the workaround doesn't work for us.
I found a work around by using quotes when assigning the values in the var file.
@baboune can you elaborate on your workaround?
@dayer4b In my case, the trick was in the .tfvars file by adding " " around integer values. By treating everything as String, then the parser can convert it to number, and it works.
Example:
In main.tf:
module "mymodule" {
auditlog-on-primary-count = "${var.auditlog-on-primary-
}
Then in variable.tf:
variable "auditlog-on-primary-count" {}
Finally in terraform.tfvars
auditlog-on-primary-count = "1"
ahh, I see. thanks!
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.
Most helpful comment
@phinze #7977 did not fix the issue. I just tested the following with Terraform 0.7.2:
Run the following at the command line:
Get error:
Same happens for boolean too.