error finding matching route for Route table and destination CIDR block randomly #225
Labels
bug
Addresses a defect in current functionality.
service/ec2
Issues and PRs that pertain to the ec2 service.
stale
Old or inactive issues managed by automation, if no further action taken these will get closed.
This issue was originally opened by @kiich as hashicorp/terraform#8226. It was migrated here as part of the provider split. The original body of the issue is below.
This is a very specific setup and it probably is the reason why i am seeing it as i can not reproduce this problem when i run it on my laptop and so on (classic excuse!! :-)).
The setup
We have a docker container that is running a deploy script which is an ansible playbook. As part of this deploy ansible playbook, we ssh to a target server where we then run terraform on.
When i run the ansible playbook on my laptop on its own, the terraform runs fine and completes as success.
But when the ansible playbook is ran inside the docker container (everything else downstream is the same as when i ran on laptop), i see error messages "error finding matching route for Route table and destination CIDR block" where the route it complains about is random.
The terraform file simply does this:
# following block takes care of igw and vpg creation resource "aws_route" "igw_or_vpg_route" { count = "${length(compact(split(",", var.cidr_block))) * var.CREATE_ROUTES}" route_table_id = "${var.route_table_id}" destination_cidr_block = "${element(split(",", var.cidr_block),count.index)}" gateway_id = "${var.gateway_id}" }
with variables like these:
CREATE_ROUTES = 1 route_table_id = "${module.routetable.route_table_id}" gateway_id = "${module.vpc.vpg_id}" cidr_block = "11.111.0.0/16,11.112.0.0/16,11.113.0.0/16,11.114.0.0/16,11.115.0.0/16,11.116.0.0/12"
and it fails with:
`
error finding matching route for Route table (rtb-36514b52) and destination CIDR block (11.111.0.0/16)
error finding matching route for Route table (rtb-36514b52) and destination CIDR block (11.112.0.0/16)
error finding matching route for Route table (rtb-36514b52) and destination CIDR block (11.114.0.0/16)
`
The route it fails on is random it seems.
I can reproduce this error all the time on the docker container but never when i run the ansible play on my laptop so i appreciate it probably is not terraform issue but i wanted to know what kind of condition can cause this.
FYI if i set:
-parallelism=1
as part of my terraform apply, this makes it work inside the container so i know it is to do with some kind of thread conditions/timing issue.
Also after getting the terraform error, when i go back to the console in AWS, the routes are actually created fine.
Terraform Version
Terraform v0.6.15
Affected Resource(s)
Expected Behavior
All routes created successfully and terraform apply finishing successfully.
Actual Behavior
All routes gets created successfully in AWS console but terraform apply failed with the following error:
error finding matching route for Route table (rtb-36514b52) and destination CIDR block (0.0.0.0/0)
error finding matching route for Route table (rtb-36514b52) and destination CIDR block (11.111.0.0/16)
error finding matching route for Route table (rtb-36514b52) and destination CIDR block (11.112.0.0/16)
error finding matching route for Route table (rtb-36514b52) and destination CIDR block (11.114.0.0/16)
Steps to Reproduce
terraform apply
Important Factoids
We call a module that creates the routes in route table.
The text was updated successfully, but these errors were encountered: