Terraform OCI:如何正确为默认路由表配置route_rules规则?
解决OCI默认路由表Terraform配置中route_rules的参数错误问题
错误原因
oci_core_default_route_table资源里,route_rules是嵌套配置块,而非键值对形式的参数,所以不能用route_rules = [{...}]这种数组赋值的写法,必须以独立块的形式定义每条路由规则。
正确配置示例
修正后的完整配置代码如下:
# 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 = "Default 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" } }
关键修改点
- 移除了
route_rules = [{...}]的赋值语法,改用独立的route_rules { ... }块定义每条路由 - 修正了原代码中
manage_default_resource_id行的换行问题(拆分两行会导致Terraform解析失败)
内容的提问来源于stack exchange,提问作者doubando
相关产品推荐
相关产品推荐

