Search code examples
terraformoracle-cloud-infrastructureinfrastructure-as-codeterraform-provider-oci

How to add new rule in existing Default Route Table in OCI using terraform


I am trying to create a rule in the existing Default Route Table in OCI using terraform.

Basically I am trying to add a rule for internet gateway so I can access it using ssh. not sure but I am not able to access TCP till I am not adding rule in default table, new table not working for me..

But In OCI provider the option is available for only create new route table with rule instead of add rule in existing / default route table

I am just able to find below option for route table in oci provider, the rest belongs to DRG.

https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_route_table

I am currently using below terraform code:

resource "oci_core_internet_gateway" "test_internet_gateway" {
    #Required
    compartment_id = var.compartment_ocid
    vcn_id = oci_core_vcn.test_vcn.id
}

resource "oci_core_route_table" "test_route_table" {
    #Required
    compartment_id = var.compartment_ocid
    vcn_id = oci_core_vcn.test_vcn.id
    #display_name = "Default Route Table for xyz"

    route_rules {
        #Required
        network_entity_id = oci_core_internet_gateway.test_internet_gateway.id
        #cidr_block = "0.0.0.0/0"
        destination = "0.0.0.0/0"
    }
}

Any way around or solution will helps !!!!


Solution

  • The displayed terraform code creates a Route Table and adds a route rule for 0.0.0.0/0. The missing piece is to map this Route Table to the subnet that is housing your VM.

    Here are a couple of thoughts:

    • You create the entire VCN and Compute VM thereby you manage your infrastructure completely. This also enables to create a subnet along side the VCN and map the route table to it.
    • Use Terraform Resource discovery to generate TF code for existing infrastructure. Once the configuration files are generated, modify it to Map the Route Table to the subnet.

    Lastly, please check this page to know about how to modify Default Resources. This could be your quick win.