Skip to content

Instantly share code, notes, and snippets.

@conorgil
Created December 16, 2015 18:10
Show Gist options
  • Save conorgil/86db9825a62963967749 to your computer and use it in GitHub Desktop.
Save conorgil/86db9825a62963967749 to your computer and use it in GitHub Desktop.
Terraform syntax bug in vpc peering module
###
# Variables
###
variable "vpc_id" {
description = "The id of the VPC"
}
variable "vpc_cidr" {
description = "The CIDR block of the VPC"
}
variable "vpc_route_table_ids" {
description = "A comma separated string of the IDs of the route tables in the VPC which should be updated to have a route for the VPC peering connection."
}
variable "peer_vpc_id" {
description = "The CIDR block of the peer VPC."
}
variable "peer_vpc_route_table_ids" {
description = "A comma separated string of the IDs of the route tables in the peer VPC which should be updated to have a route for the VPC peering connection."
}
variable "peer_vpc_cidr" {
description = "The CIDR block of the peer VPC."
}
variable "peer_owner_id" {
description = "The AWS account ID which owns the peer VPC."
}
###
# VPC peering connection
###
resource "aws_vpc_peering_connection" "main" {
auto_accept = true
vpc_id = "${var.vpc_id}"
peer_vpc_id = "${var.peer_vpc_id}"
peer_owner_id = "${var.peer_owner_id}"
}
###
# Update route tables
###
resource "aws_route" "vpc_to_peer_vpc" {
count = "${length(split(",", var.vpc_route_table_ids))}"
route_table_id = "${element(split(",", var.vpc_route_table_ids), count.index)}"
destination_cidr_block = "${var.peer_vpc_cidr}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.main.id}"
}
resource "aws_route" "peer_vpc_to_vpc" {
count = "${length(split(",", var.peer_vpc_route_table_ids))}"
route_table_id = "${element(split(",", var.peer_vpc_route_table_ids), count.index)}"
destination_cidr_block = "${var.vpc_cidr}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.main.id}"
}
###
# Module outputs
###
output "vpc_peering_connection_id" {
value = "${aws_vpc_peering_connection.main.id}"
}
@conorgil
Copy link
Author

When I run terraform plan, I get the following error:

There are warnings and/or errors related to your configuration. Please
fix these before continuing.

Errors:

  * strconv.ParseInt: parsing "${length(split(\",\", var.peer_vpc_route_table_ids))}": invalid syntax
  * strconv.ParseInt: parsing "${length(split(\",\", var.vpc_route_table_ids))}": invalid syntax

See Terraform issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment