0

To avoid creating multiple aws_route resources. I am trying to add multiple destination_cidr_block from a map to multiple route tables. I think I am in the right direction, however, it is only adding a few cidr blocks from the list to each route table and not all cidr blocks to each route table.

variable "destination_cidr_block" {
          type = map
          default = {
            destination_cidr_block = {
                 private = [
                   "0.0.0.0/0",
                   "0.0.0.0/0",
                   "0.0.0.0/0",
                   "0.0.0.0/0",]
                 private1 = [
                   "0.0.0.0/0",
                   "0.0.0.0/0"]
resource "aws_route" "private" {
  count = local.length_of_rt_cnt
  route_table_id         = element(module.private.private_route_tables_id, count.index)
  destination_cidr_block = element(var.destination_cidr_block["private1"], count.index)
  gateway_id =     module.vpc.id
}

How can I get all routes from private1 to the the multiple route tables that are already created from this module.

I apologize, everything has been destroyed and I did not saved the error. I know accomplishing multiple route tables with on destination cidr block which would look like this.

resource "aws_route" "private" {
  count = local.length_of_rt_cnt
  route_table_id         =  element(module.private.private_route_tables_id, count.index)
  destination_cidr_block = 0.0.0.0/0
  gateway_id =     module.vpc.id
} 

In this case 4 route tables will receive this cidr block. Now the question is how can I add a list of cidr block to a list of route tables

Marko E
  • 13,362
  • 2
  • 19
  • 28
mp7
  • 15
  • 4
  • 1
    Where is the code for the route tables? – Marko E Sep 07 '22 at 19:15
  • 1
    Also, are there any errors? – Marko E Sep 07 '22 at 19:39
  • it is being handled from a module and is creating multiple route tables based on the length of availability zones. So local.length_of_rt_cnt is 4. It is creating 4 route tables. How I can get ["private1] routes attached to all 4 route tables? I think my issue is the count. I think it is only looping in that list for that particular array. – mp7 Sep 07 '22 at 19:41
  • Without the code added to the question, it's pretty hard to tell. – Marko E Sep 07 '22 at 19:42
  • I apologize, everything has been destroyed and I did not saved the error. I know accomplishing multiple route tables with on destination cidr block which would look like this. `resource "aws_route" "private" { count = local.length_of_rt_cnt route_table_id = element(module.private.private_route_tables_id, count.index) destination_cidr_block = 0.0.0.0/0 gateway_id = module.vpc.id }` In this case 4 route tables will receive this cidr block. Now the question is how can I add a list of cidr block to a list of route tables – mp7 Sep 07 '22 at 19:49
  • 1
    Add the code to the question please, not in the comment. – Marko E Sep 07 '22 at 20:10

0 Answers0