Search code examples
terraformoracle-cloud-infrastructureterraform-provider-oracle

Terraform How to add Route Rule to an existing route table - Oracle OCI provider


I have an issue that not able to define a set of route_rules within oci_core_default_route_table resource

# VCN Prod Default routing table

resource "oci_core_default_route_table" "default-rt-pub-vcn" {
  manage_default_resource_id = 
  oci_core_vcn.vcn_prod.default_route_table_id
  route_rules = [{
    #Required
    network_entity_id = oci_core_internet_gateway.vcn_prod_IG.id
    #Optional
    destination_type = "CIDR_BLOCK"
    destination = "0.0.0.0/0"
    description = "Defualt route to access Internet"
   },
   {
    #Required
    network_entity_id = oci_core_local_peering_gateway.LPG_prod.id
    #Optional
    destination_type = "CIDR_BLOCK"
    destination = "192.168.100.0/24"
    description = "Route to hub VCN and hub public subnet"
   }]
}

on validation

│ Error: Unsupported argument │ │ on networking.tf line 101, in resource "oci_core_default_route_table" "default-rt-pub-vcn": │ 101: route_rules = [{ │ │ An argument named "route_rules" is not expected here. Did you mean to define a block of type "route_rules"?

How can I represent multiple route tables within the default VCN route table?


Solution

  • Based on the error, it seems you need to edit the code to look like the following:

    resource "oci_core_route_table" "default-rt-pub-vcn" {
      manage_default_resource_id = oci_core_vcn.vcn_prod.default_route_table_id
    
      route_rules {
        #Required
        network_entity_id = oci_core_internet_gateway.vcn_prod_IG.id
        #Optional
        destination_type = "CIDR_BLOCK"
        destination      = "0.0.0.0/0"
        description      = "Defualt route to access Internet"
       }
    
      route_rules {
        #Required
        network_entity_id = oci_core_local_peering_gateway.LPG_prod.id
        #Optional
        destination_type = "CIDR_BLOCK"
        destination      = "192.168.100.0/24"
        description      = "Route to hub VCN and hub public subnet"
     }
    }
    

    This means that there can be multiple route_rules blocks but not an argument (i.e., route_rules = ).