-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
strconv.ParseInt invalid syntax #5254
Comments
Hi @scalp42 - this is definitely odd. It might also have to do with #4795 which has more of a diff in the area and was merged around the same time. I'm trying to reproduce on this side and not having any luck. Can you spot any differences between the config below and yours that might be key to reproducing the issue? Also: does the syntax error happen every time or only sporadically? If you could gist up your debug log (scrubbed of any sensitive information) when you hit the error that would be helpful as well. variable "region" {
default = "us-west-2"
}
variable "infra_count" {
default = 3
}
variable "infra_public_subnet_cidr_blocks" {
default = {
"0" = "10.0.1.0/24"
"1" = "10.0.2.0/24"
"2" = "10.0.3.0/24"
}
}
variable "infra_subnet_availability_zones" {
default = {
"0" = "a"
"1" = "b"
"2" = "c"
}
}
resource "aws_vpc" "infra" {
cidr_block = "10.0.0.0/16"
}
resource "aws_internet_gateway" "infra-igw" {
vpc_id = "${aws_vpc.infra.id}"
}
resource "aws_subnet" "infra-public" {
count = "${var.infra_count}"
vpc_id = "${aws_vpc.infra.id}"
availability_zone = "${concat(var.region, lookup(var.infra_subnet_availability_zones, count.index))}"
cidr_block = "${lookup(var.infra_public_subnet_cidr_blocks, count.index)}"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.infra-igw"]
tags {
Name = "infra-public-${concat(var.region, lookup(var.infra_subnet_availability_zones, count.index))}"
Description = "infra-public-${concat(var.region, lookup(var.infra_subnet_availability_zones, count.index))}"
vpc = "infra"
terraform = "true"
}
} |
Thanks for the quick answer @phinze As of right now I can reproduce it all the time on any This gist contains the steps that got me there:
I just sent you the trace log by 📧 💌 (address listed on your Github profile). |
(Got the log in email, will analyze to help cook up a repro case.) Noting here that you can workaround the issue by temporarily inlining the value of |
Okay got a repro here (assumes region: us-west-2). Configvariable "infra_count" {
default = 3
}
resource "aws_vpc" "infra" {
cidr_block = "10.0.0.0/16"
}
resource "aws_internet_gateway" "infra-igw" {
vpc_id = "${aws_vpc.infra.id}"
}
resource "aws_subnet" "infra-public" {
count = "${var.infra_count}"
vpc_id = "${aws_vpc.infra.id}"
availability_zone = "us-west-2a"
cidr_block = "10.0.${count.index+1}.0/24"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.infra-igw"]
}
resource "aws_launch_configuration" "foo" {
image_id = "ami-03de3c63"
instance_type = "t2.nano"
}
resource "aws_autoscaling_group" "foo" {
vpc_zone_identifier = ["${aws_subnet.infra-public.*.id}"]
launch_configuration = "${aws_launch_configuration.foo.id}"
min_size = 0
max_size = 0 # Change me from 0 -> 1 after first apply
} Steps
Expected behavior:Plan is executed as displayed:
Observed behavior:
Terraform versionCurrent master: b831ba3 |
Tighter repro w/ variable "c" { default = 1 }
resource "template_file" "parent" {
count = "${var.c}"
template = "Hi"
}
resource "template_file" "child" {
template = "${join(",", template_file.parent.*.rendered)} ok"
} terraform apply # creates resources
# modify template_file.child.template to toggle add/remove extra "ok" string
terraform plan -out template.tfplan
terraform apply template.tfplan
# ...
* Error reading template_file.parent count: strconv.ParseInt: parsing "${var.c}": invalid syntax |
@phinze thanks a lot for looking into it 🙇 |
Yeap, this breaks our TF-managed infra when using HEAD. A member of my team reported this happening with interpolation functions + variables in 0.6.9 as well, this happens when a var is referenced from a resource to another >1 levels deep. will try and get a small repro case from him /cc @alexsapran |
Root cause of OP's issue is uninterpolated var making it to here, but only when using a plan file. Either there's a mistake in #5026 or it uncovered a latent dependency here on a side-effect of interpolation elsewhere. Either way, will get this sorted out before release! |
I just wanted to throw in my error which is essentially the same, although mine is not reliably reproducible. This will happen seemingly randomly, but will succeed (or produce same error on a different count var) immediately on the next apply.
|
Going to try master, thanks a lot for looking into it @mitchellh @phinze |
Related to #5254 If the count of a resource is interpolated (i.e. `${var.c}`), then it must be interpolated before any splat variable using that resource can be used (i.e. `type.name.*.attr`). The original fix for #5254 is to always ensure that this is the case. While working on a new apply builder based on the diff in `f-apply-builder`, this truth no longer always holds. Rather than always include such a resource, I believe the correct behavior instead is to use the state as a source of truth during `walkApply` operations. This change specifically is scoped to `walkApply` operation interpolations since we know the state of any multi-variable should be available. The behavior is less clear for other operations so I left the logic unchanged from prior versions.
Related to #5254 If the count of a resource is interpolated (i.e. `${var.c}`), then it must be interpolated before any splat variable using that resource can be used (i.e. `type.name.*.attr`). The original fix for #5254 is to always ensure that this is the case. While working on a new apply builder based on the diff in `f-apply-builder`, this truth no longer always holds. Rather than always include such a resource, I believe the correct behavior instead is to use the state as a source of truth during `walkApply` operations. This change specifically is scoped to `walkApply` operation interpolations since we know the state of any multi-variable should be available. The behavior is less clear for other operations so I left the logic unchanged from prior versions.
I'm running into a similar issue today, not sure if I need to create a new ticket.
Previously the count value was I'm posting first to see if anybody still has similar issues and if this is new, I can try to provide more detail. I'm just not sure what's helpful. |
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. |
Using Terraform v0.6.12-dev (e70516a), we're now getting a syntax error:
This is the config:
Git blame:
Error was not happening up to 5748487
Any ideas ?
The text was updated successfully, but these errors were encountered: