The snippet of code below will cause an error:
variable "api_public_subnets" {
default = {
cidrs = "a,b,c"
}
}
resource "aws_subnet" "api_public_subnets" {
....
count = "${length(split(",", var.api_public_subnets.cidrs))}"
....
}
Errors:
If I use not mapping it will work as expected, snippet of code below will work:
variable "api_public_subnets" {
default = "a,b,c"
}
resource "aws_subnet" "api_public_subnets" {
....
count = "${length(split(",", var.api_public_subnets))}"
....
}
For instance this code will work as-well, despite it uses mapping:
variable "api_public_subnets" {
default = {
cidrs = "a,b,c"
}
}
resource "aws_subnet" "api_public_subnets" {
....
tags {
Application = "${length(split(",", var.api_public_subnets.cidrs))}"
}
....
}
Is it a bug?
Hi @Deserved! Similarly to #3888, I can no longer reproduce this on master, using the following minimal reproduction:
provider "aws" {
region = "us-west-2"
}
variable "api_public_subnets" {
default = {
cidrs = "a,b,c"
}
}
resource "aws_subnet" "api_public_subnets" {
cidr_block = "10.0.0.0/16"
count = "${length(split(",", var.api_public_subnets.cidrs))}"
}
Which version of Terraform are you using.
Hi @jen20 I am using 0.6.6
I've just checked, it is more than 300 commits since 0.6.6 released to master. So probably it was fixed. Could you please try with 0.6.6 and see if you can replicate, if not it means problem in somewhere else.
@phinze @jen20 This is still occurring for me in 0.6.11 as well. As was alluded to in previous comments and in some of the related issues, it appears that this is related to the interpolation of a count parameter that is using a module's output.
I took the "hashicorp/best-practices" and extended it to provide a reproducible issue. Essentailly we were added an additional "peering" module which leverages outputs of the "public_subnets" and "private_subnets" modules. During the interpolation of the "count" parameter for the "aws_route" resource, we recieve the following * strconv.ParseInt: parsing "${length(split(\",\", var.pub_route_table_ids))}": invalid syntax
If I were to comment out the resource itself and take a look at the "interpolation_debug" output in the state, it is the appropriate value (and the plan proceeds as expected)
Diff: https://github.com/hashicorp/best-practices/compare/master...jrnt30:GH-3884-Module-interpolation-issues
Erroring Line: https://github.com/hashicorp/best-practices/compare/master...jrnt30:GH-3884-Module-interpolation-issues#diff-a40ed86341ef14520b793a2a198f68f6R31
Full debug log: https://gist.github.com/jrnt30/a55960ce3108639723bf
As a note, I made an attempt at "pre-computing" the length value in the "parent" module and passing in a set of "count" variables. In doing so, ran across #2301
I can provide another branch for that derivation of this issue if it's helpful
Running into this issue also in Terraform v0.6.14
And also on v0.6.15
The same in Terraform v0.6.16
This works on master now with 0.7:
variable "foo" {
default = {
values = "a,b,c"
}
}
resource "null_resource" "foo" {
count = "${length(split(",", var.foo["values"]))}"
}
I think this is good to close.
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
The same in Terraform v0.6.16