Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions examples/tenant_policies_l3out_node_routing_policy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
terraform {
required_providers {
mso = {
source = "CiscoDevNet/mso"
}
}
}

provider "mso" {
username = "" # <MSO username>
password = "" # <MSO pwd>
url = "" # <MSO URL>
insecure = true
}

data "mso_tenant" "example_tenant" {
name = "example_tenant"
}

# Tenant template example

resource "mso_template" "tenant_template" {
template_name = "tenant_template"
template_type = "tenant"
tenant_id = data.mso_tenant.example_tenant.id
}

# L3Out Node Routing Policy example with all configuration blocks

resource "mso_tenant_policies_l3out_node_routing_policy" "node_policy_full" {
template_id = mso_template.tenant_template.id
name = "production_node_routing_policy"
description = "Production L3Out Node Routing Policy with BFD and BGP"
as_path_multipath_relax = true

bfd_multi_hop_settings {
admin_state = "enabled"
detection_multiplier = 3
min_receive_interval = 250
min_transmit_interval = 250
}

bgp_node_settings {
graceful_restart_helper = true
keep_alive_interval = 60
hold_interval = 180
stale_interval = 300
max_as_limit = 0
}
}
128 changes: 128 additions & 0 deletions mso/datasource_mso_tenant_policies_l3out_node_routing_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package mso

import (
"fmt"
"log"

"github.com/ciscoecosystem/mso-go-client/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func datasourceMSOL3OutNodeRoutingPolicy() *schema.Resource {
return &schema.Resource{
Read: dataSourceMSOL3OutNodeRoutingPolicyRead,

Schema: map[string]*schema.Schema{
"template_id": {
Type: schema.TypeString,
Required: true,
Description: "The ID of the tenant policy template.",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the L3Out Node Routing Policy.",
},
"uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of the L3Out Node Routing Policy.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the L3Out Node Routing Policy.",
},
"as_path_multipath_relax": {
Type: schema.TypeBool,
Computed: true,
Description: "BGP Best Path Control - AS path multipath relax.",
},
"bfd_multi_hop_settings": {
Type: schema.TypeList,
Computed: true,
Description: "BFD multi-hop configuration.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"admin_state": {
Type: schema.TypeString,
Computed: true,
Description: "Administrative state.",
},
"detection_multiplier": {
Type: schema.TypeInt,
Computed: true,
Description: "Detection multiplier.",
},
"min_receive_interval": {
Type: schema.TypeInt,
Computed: true,
Description: "Minimum receive interval in microseconds.",
},
"min_transmit_interval": {
Type: schema.TypeInt,
Computed: true,
Description: "Minimum transmit interval in microseconds.",
},
},
},
},
"bgp_node_settings": {
Type: schema.TypeList,
Computed: true,
Description: "BGP node configuration.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"graceful_restart_helper": {
Type: schema.TypeBool,
Computed: true,
Description: "Graceful restart helper mode.",
},
"keep_alive_interval": {
Type: schema.TypeInt,
Computed: true,
Description: "BGP keepalive interval in seconds.",
},
"hold_interval": {
Type: schema.TypeInt,
Computed: true,
Description: "BGP hold interval in seconds.",
},
"stale_interval": {
Type: schema.TypeInt,
Computed: true,
Description: "BGP stale interval in seconds.",
},
"max_as_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum AS path limit.",
},
},
},
},
},
}
}

func dataSourceMSOL3OutNodeRoutingPolicyRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[DEBUG] MSO L3Out Node Routing Policy Data Source - Beginning Read")
msoClient := m.(*client.Client)

templateId := d.Get("template_id").(string)
policyName := d.Get("name").(string)

response, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/templates/%s", templateId))
if err != nil {
return err
}

policy, err := GetPolicyByName(response, policyName, "tenantPolicyTemplate", "template", "l3OutNodePolGroups")
if err != nil {
return err
}

setL3OutNodeRoutingPolicyData(d, policy, templateId)
log.Printf("[DEBUG] MSO L3Out Node Routing Policy Data Source - Read Complete: %v", d.Id())
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package mso

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccMSOTenantPoliciesL3OutNodeRoutingPolicyDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: L3Out Node Routing Policy Data Source") },
Config: testAccMSOTenantPoliciesL3OutNodeRoutingPolicyDataSource(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "name", "test_node_routing_policy"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "description", "Test L3Out Node Routing Policy"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "uuid"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "template_id"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "as_path_multipath_relax", "false"),

resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bfd_multi_hop_settings.#", "1"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bfd_multi_hop_settings.0.admin_state", "enabled"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bfd_multi_hop_settings.0.detection_multiplier", "3"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bfd_multi_hop_settings.0.min_receive_interval", "250"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bfd_multi_hop_settings.0.min_transmit_interval", "250"),

resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bgp_node_settings.#", "1"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bgp_node_settings.0.graceful_restart_helper", "true"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bgp_node_settings.0.keep_alive_interval", "60"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bgp_node_settings.0.hold_interval", "180"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bgp_node_settings.0.stale_interval", "300"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_l3out_node_routing_policy.node_policy", "bgp_node_settings.0.max_as_limit", "0"),
),
},
},
})
}

func testAccMSOTenantPoliciesL3OutNodeRoutingPolicyDataSource() string {
return fmt.Sprintf(`%s
data "mso_tenant_policies_l3out_node_routing_policy" "node_policy" {
template_id = mso_tenant_policies_l3out_node_routing_policy.node_policy.template_id
name = "test_node_routing_policy"
}`, testAccMSOTenantPoliciesL3OutNodeRoutingPolicyConfigCreate())
}
2 changes: 2 additions & 0 deletions mso/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func Provider() terraform.ResourceProvider {
"mso_tenant_policies_ipsla_track_list": resourceMSOIPSLATrackList(),
"mso_tenant_policies_l3out_interface_routing_policy": resourceMSOL3OutInterfaceRoutingPolicy(),
"mso_fabric_policies_interface_setting": resourceMSOInterfaceSetting(),
"mso_tenant_policies_l3out_node_routing_policy": resourceMSOL3OutNodeRoutingPolicy(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -217,6 +218,7 @@ func Provider() terraform.ResourceProvider {
"mso_tenant_policies_ipsla_track_list": datasourceMSOIPSLATrackList(),
"mso_tenant_policies_l3out_interface_routing_policy": datasourceMSOL3OutInterfaceRoutingPolicy(),
"mso_fabric_policies_interface_setting": datasourceMSOInterfaceSetting(),
"mso_tenant_policies_l3out_node_routing_policy": datasourceMSOL3OutNodeRoutingPolicy(),
},

ConfigureFunc: configureClient,
Expand Down
Loading
Loading