【问题标题】:How to add new rule in existing Default Route Table in OCI using terraform如何使用 terraform 在 OCI 中的现有默认路由表中添加新规则
【发布时间】:2021-12-06 01:26:34
【问题描述】:

我正在尝试使用 terraform 在 OCI 中现有的默认路由表中创建规则。

基本上,我正在尝试为互联网网关添加一条规则,以便我可以使用 ssh 访问它。不确定,但我无法访问 TCP,直到我没有在默认表中添加规则,新表对我不起作用..

但在 OCI 提供程序中,该选项仅可用于使用规则创建新路由表,而不是在现有/默认路由表中添加规则

我只能在 oci 提供程序中找到以下路由表选项,其余的属于 DRG。

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

我目前正在使用以下 terraform 代码:​​

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"
    }
}

任何解决方法或解决方案都会有所帮助!!!!

【问题讨论】:

    标签: terraform oracle-cloud-infrastructure infrastructure-as-code terraform-provider-oci


    【解决方案1】:

    显示的 terraform 代码会创建一个路由表并为 0.0.0.0/0 添加一个路由规则。缺少的部分是将此路由表映射到容纳您的 VM 的子网。

    以下是一些想法:

    • 您可以创建整个 VCN 和计算 VM,从而完全管理您的基础架构。这还可以在 VCN 旁边创建一个子网并将路由表映射到它。
    • 使用Terraform Resource discovery 为现有基础架构生成 TF 代码。生成配置文件后,将其修改为将路由表映射到子网。

    最后,请check this page了解如何修改默认资源。这可能是您的快速胜利。

    【讨论】:

    • 您能否查看docs.oracle.com/en-us/iaas/Content/API/SDKDocs/… 上的示例以修改默认DHCP 选项?默认路由表需要类似的东西。验证它是否是与您的 VM 所在的子网关联的默认路由表非常重要。
    • 你的最后一页链接成功了 .. 谢谢 :D
    • 只是想知道 - 页面中指定的“oci_core_default_route_table”资源在 oci 提供程序注册表文档中不存在。知道为什么吗?
    • 我已添加代码作为我用于此问题的答案
    【解决方案2】:

    扩展了@bmuthuv的答案

    下面的页面有一些线索,我们可以如何管理默认 VCN 资源:

    https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformbestpractices_topic-vcndefaults.htm

    我已将资源 oci_core_route_table 替换为 oci_core_default_route_table。奇怪的是资源“oci_core_default_route_table”并没有直接出现在注册表提供者文档中,您需要在oci注册页面上搜索“管理默认VCN资源”如下:

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

    resource "oci_core_default_route_table" "this" {
      #SOURCE PAGE : https://www.tfwriter.com/oci/r/oci_core_default_route_table.html
    
      manage_default_resource_id = oci_core_subnet.test_subnet.route_table_id
    
      route_rules {
        #Required
        network_entity_id = oci_core_internet_gateway.test_internet_gateway.id
        destination = "0.0.0.0/0"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-12
      • 2019-01-21
      • 2023-03-29
      • 2022-11-05
      • 2021-06-16
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多