-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
panic in cidrsubnet function #18107
Comments
Hi @tonygyerr! Thanks for reporting this. Are you able to share the source code for the |
/*
locals
*/
locals {
base_cidr = "${aws_vpc.api-east-vpc.cidr_block}"
cidr_block_public_ecs = "${cidrsubnet(var.base_cidr_pub, var.newbits_pub, var.netnum_public_ecs)}"
cidr_block_private_ecs = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_ecs)}"
cidr_block_private_db = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_db)}"
cidr_block_private_lb = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_lb)}"
}
/*
ecs subnet public
*/
resource "aws_subnet" "ecs_subnet_pub" {
count = "${var.amount_public_ecs_subnets}"
cidr_block = "${cidrsubnet(local.cidr_block_public_ecs, ceil(log(var.max_subnets_pub, var.newbits_pub)), count.index)}"
vpc_id = "${aws_vpc.api-east-vpc.id}"
availability_zone = "${data.aws_availability_zones.main.names[count.index]}"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.api-nonprd-east-ig"]
tags {
Name = "${var.tags["Name"]}-ecs-pub-${count.index}-subnet"
}
}
/*
ecs subnet private
*/
resource "aws_subnet" "ecs_subnet_prv" {
count = "${var.amount_private_ecs_subnets}"
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_ecs + count.index))}"
//cidr_block = "${cidrsubnet(var.base_cidr_prv, ceil(log(var.max_subnets_prv, 2)), (6 + count.index))}"
vpc_id = "${aws_vpc.api-east-vpc.id}"
availability_zone = "${data.aws_availability_zones.main.names[count.index]}"
map_public_ip_on_launch = false
tags {
Name = "${var.tags["Name"]}-ecs-prv-${count.index}-subnet"
}
}
/*
database subnet private
*/
resource "aws_subnet" "db_subnet_prv" {
count = "${var.amount_private_db_subnets}"
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_db + count.index))}"
//cidr_block = "${cidrsubnet(var.base_cidr_prv, ceil(log(var.max_subnets_prv, 2)), (9 + count.index))}" #base_cidr_prv 10.20.100.0/20
vpc_id = "${aws_vpc.api-east-vpc.id}"
availability_zone = "${data.aws_availability_zones.main.names[count.index]}"
map_public_ip_on_launch = false
tags {
Name = "${var.tags["Name"]}-db-prv-${count.index}-subnet"
}
}
/*
load balancer subnet private
*/
resource "aws_subnet" "lb_subnet_prv" {
count = "${var.amount_private_lb_subnets}"
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_lb + count.index))}"
//cidr_block = "${cidrsubnet(var.base_cidr_prv, ceil(log(var.max_subnets_prv, 2)), (12 + count.index))}"
vpc_id = "${aws_vpc.api-east-vpc.id}"
availability_zone = "${data.aws_availability_zones.main.names[count.index]}"
map_public_ip_on_launch = false
tags {
Name = "${var.tags["Name"]}-alb-prv-${count.index}-subnet"
}
}
/*
rds aurora api notification database subnet group
*/
resource "aws_db_subnet_group" "apidb_subnet_group" {
name = "apidb_subnet_group"
description = "apidb subnet group"
subnet_ids = ["${element(aws_subnet.db_subnet_prv.*.id, count.index)}"]
}
/*
variables
*/
variable "base_cidr_pub" {
description = "cidr for vpc"
type = "string"
default = "10.20.100.0/20"
}
variable "newbits_pub" {
description = "see https://www.terraform.io/docs/configuration/interpolation.html#cidrsubnet_iprange_newbits_netnum_"
type = "string"
default = 3
}
variable "newbits_prv" {
description = "see https://www.terraform.io/docs/configuration/interpolation.html#cidrsubnet_iprange_newbits_netnum_"
type = "string"
default = 1
//default = 4
}
variable "max_subnets_prv" {
description = "Maximum number of subnets which can be created for CIDR blocks calculation. Default to length of `names` argument"
default = "16"
}
variable "netnum_public_ecs" {
type = "string"
default = "1"
}
variable "netnum_private_ecs" {
type = "string"
default = "6"
}
variable "netnum_private_db" {
type = "string"
default = "9"
}
variable "netnum_private_lb" {
type = "string"
default = "12"
} |
Thanks @tonygyerr! Do you happen to know what values those various variables were set to when you ran Terraform and got this crash? Specifically, the variables that are used with I'm trying to figure out which of the |
i updated the variables in the prior message. |
Thanks! I was able to reproduce the crash with the following modified configuration. Unfortunately, I've not yet been able to identify which of the Unfortunately I need to break now, so I'll need to return to this another day and investigate further. Thanks again for reporting this! provider "aws" {
region = "us-east-1"
}
/*
locals
*/
locals {
base_cidr = "${aws_vpc.aee-ece-outage-east-vpc.cidr_block}"
cidr_block_public_ecs = "${cidrsubnet(var.base_cidr_pub, var.newbits_pub, var.netnum_public_ecs)}"
cidr_block_private_ecs = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_ecs)}"
cidr_block_private_db = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_db)}"
cidr_block_private_lb = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_lb)}"
}
/*
ecs subnet public
*/
resource "aws_subnet" "ecs_subnet_pub" {
count = 1
cidr_block = "${cidrsubnet(local.cidr_block_public_ecs, ceil(log(var.max_subnets_pub, var.newbits_pub)), count.index)}"
vpc_id = "vpc-1234"
availability_zone = "us-east-1a"
map_public_ip_on_launch = true
}
/*
ecs subnet private
*/
resource "aws_subnet" "ecs_subnet_prv" {
count = 1
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_ecs + count.index))}"
vpc_id = "vpc-1234"
availability_zone = "us-east-1a"
map_public_ip_on_launch = false
}
/*
database subnet private
*/
resource "aws_subnet" "db_subnet_prv" {
count = 1
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_db + count.index))}"
vpc_id = "vpc-1234"
availability_zone = "us-east-1a"
map_public_ip_on_launch = false
}
/*
load balancer subnet private
*/
resource "aws_subnet" "lb_subnet_prv" {
count = 1
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_lb + count.index))}"
vpc_id = "vpc-1234"
availability_zone = "us-east-1a"
map_public_ip_on_launch = false
}
/*
rds aurora api notification database subnet group
*/
resource "aws_db_subnet_group" "apidb_subnet_group" {
name = "apidb_subnet_group"
description = "apidb subnet group"
subnet_ids = ["${element(aws_subnet.db_subnet_prv.*.id, count.index)}"]
}
/*
variables
*/
variable "base_cidr_pub" {
description = "cidr for vpc"
type = "string"
default = "10.20.100.0/20"
}
variable "base_cidr_prv" {
description = "cidr for vpc"
type = "string"
default = "10.20.100.0/20"
}
variable "newbits_pub" {
type = "string"
default = 3
}
variable "newbits_prv" {
type = "string"
default = 1
}
variable "max_subnets_prv" {
description = "Maximum number of subnets which can be created for CIDR blocks calculation. Default to length of `names` argument"
default = "16"
}
variable "netnum_public_ecs" {
type = "string"
default = "1"
}
variable "netnum_private_ecs" {
type = "string"
default = "6"
}
variable "netnum_private_db" {
type = "string"
default = "9"
}
variable "netnum_private_lb" {
type = "string"
default = "12"
}
variable "max_subnets_pub" {
type = "string"
default = "16"
} |
i believe the issue is when utilizing the locals.tfworkaround while cidrsubnet bug for locals.tf is being worked on
-- tags { /* tags { /* tags { /* tags { /* variable "base_cidr_pub" { variable "base_cidr_prv" { variable "newbits_pub" { variable "newbits_prv" { variable "netnum_public_ecs" { variable "netnum_private_ecs" { variable "netnum_private_db" { variable "netnum_private_lb" { |
@apparentlymart please update the base_cidr to read "${aws_vpc.api-east-vpc.cidr_block}" when you get a chance in your response above when you get a chance please. locals { |
Hi again! Sorry for the long silence here. Since this issue is in the underlying CIDR utility library rather than Terraform itself, it's still present in the master branch after we've merged the configuration language improvements work for the forthcoming v0.12.0 release, but the new language interpreter runs functions in a Here's the configuration I used: provider "aws" {
region = "us-west-2"
}
locals {
base_cidr = "10.1.0.0/16"
cidr_block_public_ecs = "${cidrsubnet(var.base_cidr_pub, var.newbits_pub, var.netnum_public_ecs)}"
cidr_block_private_ecs = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_ecs)}"
cidr_block_private_db = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_db)}"
cidr_block_private_lb = "${cidrsubnet(var.base_cidr_prv, 4, var.netnum_private_lb)}"
}
resource "aws_subnet" "ecs_subnet_pub" {
count = 1
cidr_block = "${cidrsubnet(local.cidr_block_public_ecs, ceil(log(var.max_subnets_pub, var.newbits_pub)), count.index)}"
vpc_id = "vpc-1234"
availability_zone = "us-east-1a"
map_public_ip_on_launch = true
}
resource "aws_subnet" "ecs_subnet_prv" {
count = 1
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_ecs + count.index))}"
vpc_id = "vpc-1234"
availability_zone = "us-east-1a"
map_public_ip_on_launch = false
}
resource "aws_subnet" "db_subnet_prv" {
count = 1
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_db + count.index))}"
vpc_id = "vpc-1234"
availability_zone = "us-east-1a"
map_public_ip_on_launch = false
}
resource "aws_subnet" "lb_subnet_prv" {
count = 1
cidr_block = "${cidrsubnet(local.cidr_block_private_ecs, ceil(log(var.max_subnets_prv, var.newbits_prv)), (var.netnum_private_lb + count.index))}"
vpc_id = "vpc-1234"
availability_zone = "us-east-1a"
map_public_ip_on_launch = false
}
resource "aws_db_subnet_group" "apidb_subnet_group" {
count = 1
name = "apidb_subnet_group"
description = "apidb subnet group"
subnet_ids = ["${element(aws_subnet.db_subnet_prv.*.id, count.index)}"]
}
variable "base_cidr_pub" {
description = "cidr for vpc"
type = "string"
default = "10.20.100.0/20"
}
variable "base_cidr_prv" {
description = "cidr for vpc"
type = "string"
default = "10.20.100.0/20"
}
variable "newbits_pub" {
type = "string"
default = 3
}
variable "newbits_prv" {
type = "string"
default = 1
}
variable "max_subnets_prv" {
description = "Maximum number of subnets which can be created for CIDR blocks calculation. Default to length of `names` argument"
default = "16"
}
variable "netnum_public_ecs" {
type = "string"
default = "1"
}
variable "netnum_private_ecs" {
type = "string"
default = "6"
}
variable "netnum_private_db" {
type = "string"
default = "9"
}
variable "netnum_private_lb" {
type = "string"
default = "12"
}
variable "max_subnets_pub" {
type = "string"
default = "16"
} Here are the errors I got when applying it:
We'll return to this in a little while and use this information to construct a more minimal reproduction case and then find a fix for it. One thing I noticed though from quick reading of these messages is that |
This panic seems to be fixed in the 0.13 beta release (perhaps via apparentlymart/go-cidr#16) and now results in a more useful error:
I think the error here is that |
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. |
Terraform Version
Terraform v0.11.7
Terraform Configuration Files
...
Debug Output
Crash Output
Expected Behavior
Actual Behavior
Steps to Reproduce
terraform -v
terraform providers
terraform plan
Additional Context
References
The text was updated successfully, but these errors were encountered: