diff --git a/nsxt/resource_nsxt_policy_gateway_route_map.go b/nsxt/resource_nsxt_policy_gateway_route_map.go index 57cdbecb4..2788485b7 100644 --- a/nsxt/resource_nsxt_policy_gateway_route_map.go +++ b/nsxt/resource_nsxt_policy_gateway_route_map.go @@ -115,11 +115,13 @@ func getPolicyRouteMapEntrySchema() *schema.Resource { "local_preference": { Type: schema.TypeInt, Optional: true, + Computed: true, Description: "Local preference indicates the degree of preference for one BGP route over other BGP routes", }, "med": { Type: schema.TypeInt, Optional: true, + Computed: true, Description: "A lower Multi exit descriminator (MED) is preferred over a higher value", }, "prefer_global_v6_next_hop": { @@ -159,7 +161,7 @@ func resourceNsxtPolicyGatewayRouteMapExists(tier0Id string, id string, connecto return false, logAPIError("Error retrieving resource", err) } -func policyGatewayRouteMapBuildEntry(schemaEntry map[string]interface{}) model.RouteMapEntry { +func policyGatewayRouteMapBuildEntry(d *schema.ResourceData, entryNo int, schemaEntry map[string]interface{}) model.RouteMapEntry { action := schemaEntry["action"].(string) obj := model.RouteMapEntry{ @@ -192,14 +194,12 @@ func policyGatewayRouteMapBuildEntry(schemaEntry map[string]interface{}) model.R data := schemaEntry["set"].([]interface{})[0].(map[string]interface{}) asPathPrepend := data["as_path_prepend"].(string) community := data["community"].(string) - localPreference := int64(data["local_preference"].(int)) - med := int64(data["med"].(int)) + localPreferenceValue, lpSet := d.GetOk(fmt.Sprintf("entry.%d.set.0.local_preference", entryNo)) + medValue, medSet := d.GetOk(fmt.Sprintf("entry.%d.set.0.med", entryNo)) globalIPv6 := data["prefer_global_v6_next_hop"].(bool) weight := int64(data["weight"].(int)) entrySet := model.RouteMapEntrySet{ - LocalPreference: &localPreference, - Med: &med, PreferGlobalV6NextHop: &globalIPv6, Weight: &weight, } @@ -210,6 +210,14 @@ func policyGatewayRouteMapBuildEntry(schemaEntry map[string]interface{}) model.R if len(community) > 0 { entrySet.Community = &community } + if lpSet { + localPreference := int64(localPreferenceValue.(int)) + entrySet.LocalPreference = &localPreference + } + if medSet { + med := int64(medValue.(int)) + entrySet.Med = &med + } obj.Set = &entrySet } @@ -223,8 +231,8 @@ func resourceNsxtPolicyGatewayRouteMapPatch(gwID string, id string, d *schema.Re schemaEntries := d.Get("entry").([]interface{}) var entries []model.RouteMapEntry - for _, entry := range schemaEntries { - entries = append(entries, policyGatewayRouteMapBuildEntry(entry.(map[string]interface{}))) + for entryNo, entry := range schemaEntries { + entries = append(entries, policyGatewayRouteMapBuildEntry(d, entryNo, entry.(map[string]interface{}))) } obj := model.Tier0RouteMap{ diff --git a/nsxt/resource_nsxt_policy_gateway_route_map_test.go b/nsxt/resource_nsxt_policy_gateway_route_map_test.go index 373494fb0..3fe6049c6 100644 --- a/nsxt/resource_nsxt_policy_gateway_route_map_test.go +++ b/nsxt/resource_nsxt_policy_gateway_route_map_test.go @@ -28,7 +28,24 @@ func TestAccResourceNsxtPolicyGatewayRouteMap_basic(t *testing.T) { testAccNsxtPolicyGatewayRouteMapExists(displayName, testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", displayName), resource.TestCheckResourceAttr(testResourceName, "description", "terraform created"), - + resource.TestCheckResourceAttr(testResourceName, "entry.#", "3"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.action", "PERMIT"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.set.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.set.0.local_preference", "100"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.set.0.med", "0"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.prefix_list_matches.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.action", "DENY"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.community_list_match.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.community_list_match.0.criteria", "11:22"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.set.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.set.0.local_preference", "1122"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.set.0.as_path_prepend", "100 100"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.set.0.community", "11:22"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.set.0.prefer_global_v6_next_hop", "true"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.set.0.weight", "12"), + resource.TestCheckResourceAttr(testResourceName, "entry.1.set.0.med", "120"), + resource.TestCheckResourceAttr(testResourceName, "entry.2.action", "DENY"), + resource.TestCheckResourceAttr(testResourceName, "entry.2.set.#", "0"), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), resource.TestCheckResourceAttrSet(testResourceName, "revision"), @@ -41,7 +58,13 @@ func TestAccResourceNsxtPolicyGatewayRouteMap_basic(t *testing.T) { testAccNsxtPolicyGatewayRouteMapExists(displayName, testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", displayName), resource.TestCheckResourceAttr(testResourceName, "description", "terraform updated"), - + resource.TestCheckResourceAttr(testResourceName, "entry.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.action", "PERMIT"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.set.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.set.0.local_preference", "100"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.set.0.med", "5"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.community_list_match.#", "2"), + resource.TestCheckResourceAttr(testResourceName, "entry.0.prefix_list_matches.#", "0"), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), resource.TestCheckResourceAttrSet(testResourceName, "revision"), @@ -163,6 +186,10 @@ resource "nsxt_policy_gateway_route_map" "test" { entry { action = "PERMIT" prefix_list_matches = [nsxt_policy_gateway_prefix_list.test.path] + + set { + weight = 12 + } } entry { @@ -181,6 +208,14 @@ resource "nsxt_policy_gateway_route_map" "test" { weight = 12 } } + + entry { + action = "DENY" + community_list_match { + criteria = "22:*" + match_operator = "MATCH_COMMUNITY_REGEX" + } + } tag { scope = "scope1" @@ -219,6 +254,10 @@ resource "nsxt_policy_gateway_route_map" "test" { criteria = "11:*" match_operator = "MATCH_LARGE_COMMUNITY_REGEX" } + set { + weight = 12 + med = 5 + } } tag {