Skip to content

Commit c5785e8

Browse files
nitimisMaxrovr
authored andcommitted
Bug fix for Create route table when route rule contains route_type.
1 parent f559662 commit c5785e8

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

examples/networking/route_table/route_table.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,30 @@ resource "oci_core_route_table" "example_route_table" {
5757
}
5858
}
5959

60+
resource "oci_core_vcn" "example_vcn_2" {
61+
cidr_block = "10.1.0.0/16"
62+
compartment_id = var.compartment_ocid
63+
display_name = "exampleVCN"
64+
dns_label = "tfexamplevcn"
65+
}
66+
67+
resource "oci_core_internet_gateway" "example_ig_2" {
68+
compartment_id = var.compartment_ocid
69+
display_name = "exampleIG"
70+
vcn_id = oci_core_vcn.example_vcn_2.id
71+
}
72+
73+
resource "oci_core_route_table" "example_route_table_static" {
74+
compartment_id = var.compartment_ocid
75+
vcn_id = oci_core_vcn.example_vcn_2.id
76+
display_name = "exampleRouteTable"
77+
78+
route_rules {
79+
description = var.route_table_route_rules_description
80+
destination = "10.0.0.0/0"
81+
destination_type = "CIDR_BLOCK"
82+
network_entity_id = oci_core_internet_gateway.example_ig_2.id
83+
route_type = "STATIC"
84+
}
85+
}
86+

internal/integrationtest/core_route_table_resource_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
339339
route_rules {
340340
cidr_block = "0.0.0.0/0"
341341
network_entity_id = "${oci_core_internet_gateway.internet-gateway1.id}"
342+
route_type = "STATIC"
342343
}
343344
}` + defaultRouteTable,
344345
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
@@ -354,6 +355,12 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
354355
[]string{
355356
"network_entity_id",
356357
}),
358+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "route_rules", map[string]string{
359+
"route_type": "STATIC",
360+
},
361+
[]string{
362+
"network_entity_id",
363+
}),
357364
resource.TestCheckResourceAttrSet(defaultResourceName, "manage_default_resource_id"),
358365
resource.TestCheckResourceAttrSet(defaultResourceName, "compartment_id"),
359366
resource.TestCheckResourceAttr(defaultResourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
@@ -414,6 +421,12 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
414421
[]string{
415422
"network_entity_id",
416423
}),
424+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "route_rules", map[string]string{
425+
"route_type": "STATIC",
426+
},
427+
[]string{
428+
"network_entity_id",
429+
}),
417430
resource.TestCheckResourceAttr(resourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
418431
resource.TestCheckResourceAttrSet(defaultResourceName, "manage_default_resource_id"),
419432
resource.TestCheckResourceAttr(defaultResourceName, "compartment_id", compartmentIdU),
@@ -431,6 +444,12 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
431444
[]string{
432445
"network_entity_id",
433446
}),
447+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "route_rules", map[string]string{
448+
"route_type": "STATIC",
449+
},
450+
[]string{
451+
"network_entity_id",
452+
}),
434453
resource.TestCheckResourceAttr(defaultResourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
435454
),
436455
},

internal/service/core/core_route_table_resource.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ func RouteRuleToMap(obj oci_core.RouteRule) map[string]interface{} {
444444
result["network_entity_id"] = string(*obj.NetworkEntityId)
445445
}
446446

447+
if obj.RouteType != "" {
448+
result["route_type"] = string(obj.RouteType)
449+
}
447450
return result
448451
}
449452

@@ -480,10 +483,14 @@ func routeRulesHashCodeForSets(v interface{}) int {
480483
buf.WriteString(fmt.Sprintf("%v-", networkEntityId))
481484
}
482485

483-
if routeType, ok := m["route_type"]; ok && routeType != "" {
484-
buf.WriteString(fmt.Sprintf("%v-", routeType))
486+
routeType := ""
487+
if val, ok := m["route_type"]; ok && val != "" {
488+
routeType = val.(string)
485489
}
486-
490+
if routeType == "" {
491+
routeType = "STATIC" // normalize default
492+
}
493+
buf.WriteString(fmt.Sprintf("%v-", routeType))
487494
return utils.GetStringHashcode(buf.String())
488495

489496
}

0 commit comments

Comments
 (0)