Hello,
I have this code block working in terraform version < 0.12
variable "region" {
}
variable "instance_number_onset" {
default = "0"
}
variable "gw_count" {
default = 1
}
variable "vpc_names" {
default = ["Dev", "Stage", "Prod", "Ops"]
}
locals {
description = "Transit-Gateway-"
}
resource "aws_ec2_transit_gateway" "transit_gw" {
count = "${var.gw_count}"
description = "${local.description}${format("%03d", var.instance_number_onset + count.index)}"
auto_accept_shared_attachments = "enable"
default_route_table_association = "disable"
default_route_table_propagation = "disable"
dns_support = "enable"
vpn_ecmp_support = "enable"
tags = "${
map(
"Name", "Transit-Gateway-${format("%03d", var.instance_number_onset + count.index)}",
"Region", "${var.region}",
"Description", "${local.description}${format("%03d", var.instance_number_onset + count.index)}",
"Managed_by", "terraform",
)}"
}
resource "aws_ec2_transit_gateway_route_table" "rtb" {
count = "${var.gw_count * length(var.vpc_names)}"
transit_gateway_id = "${element(aws_ec2_transit_gateway.transit_gw.*.id, count.index / length(var.vpc_names))}"
tags = "${
map(
"Name", "-${element(aws_ec2_transit_gateway.transit_gw.*.id, count.index / length(var.vpc_names))}-rtb",
"Region", "${var.region}",
"Description", "-${local.description}${element(aws_ec2_transit_gateway.transit_gw.*.id, count.index / length(var.vpc_names))}-rtb",
"Managed_by", "terraform",
"VPC", ""
)}"
lifecycle {
create_before_destroy = true
ignore_changes = [
"tags",
]
}
}
This will create 4x aws_ec2_transit_gateway_route_table
resources for every 1 aws_ec2_transit_gateway
With terraform 0.12 upgrade, it has converted the code to:
resource "aws_ec2_transit_gateway_route_table" "rtb" {
count = var.gw_count * length(var.vpc_names)
transit_gateway_id = element(
aws_ec2_transit_gateway.transit_gw.*.id,
count.index / length(var.vpc_names),
)
tags = {
"Name" = "-${element(
aws_ec2_transit_gateway.transit_gw.*.id,
count.index / length(var.vpc_names),
)}-rtb"
"Region" = var.region
"Description" = "-${local.description}${element(
aws_ec2_transit_gateway.transit_gw.*.id,
count.index / length(var.vpc_names),
)}-rtb"
"Managed_by" = "terraform"
"VPC" = ""
}
lifecycle {
create_before_destroy = true
ignore_changes = [tags]
}
}
The errors im now receiving are:
Error: Error in function call
on ../../../../modules/transit-gateway/main.tf line 24, in resource "aws_ec2_transit_gateway_route_table" "rtb":
24: transit_gateway_id = element(
25:
26:
27:
|----------------
| aws_ec2_transit_gateway.transit_gw is tuple with 1 element
| count.index is 1
| var.vpc_names is tuple with 5 elements
Call to function "element" failed: invalid index: value must be a whole
number, between -9223372036854775808 and 9223372036854775807.
How can I revise my module to achieve the same result as before?
Thank you