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
88 changes: 88 additions & 0 deletions examples/tenant_policies_ipsla_track_list/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
terraform {
required_providers {
mso = {
source = "CiscoDevNet/mso"
}
}
}

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

data "mso_site" "ansible_test" {
name = "ansible_test"
}

resource "mso_tenant" "mso_tenant" {
name = "mso_tenant"
display_name = "mso_tenant"
site_associations {
site_id = data.mso_site.ansible_test.id
}
}

resource "mso_schema" "mso_schema" {
name = "mso_schema"
template {
name = "mso_schema_template"
display_name = "mso_schema_template"
tenant_id = mso_tenant.mso_tenant.id
}
}

resource "mso_schema_template_vrf" "example_vrf" {
name = "example_vrf"
display_name = "example_vrf"
schema_id = mso_schema.mso_schema.id
template = "mso_schema_template"
}

resource "mso_schema_template_bd" "example_bd" {
schema_id = mso_schema.mso_schema.id
template_name = "mso_schema_template"
name = "example_bd"
display_name = "example_bd"
layer2_unknown_unicast = "proxy"
vrf_name = mso_schema_template_vrf.example_vrf.name
}

resource "mso_template" "tenant_policy_template" {
template_name = "tenant_policy_template"
template_type = "tenant"
tenant_id = mso_tenant.mso_tenant.id
}

resource "mso_tenant_policies_ipsla_monitoring_policy" "ipsla_monitoring_policy" {
template_id = mso_template.tenant_policy_template.id
name = "ipsla_monitoring_policy"
sla_type = "http"
destination_port = 80
http_version = "HTTP11"
http_uri = "/example"
sla_frequency = 120
detect_multiplier = 4
request_data_size = 64
type_of_service = 18
operation_timeout = 100
threshold = 100
ipv6_traffic_class = 255
}

resource "mso_tenant_policies_ipsla_track_list" "ipsla_track_list" {
template_id = mso_template.tenant_policy_template.id
name = "ipsla_track_list"
description = "Terraform test IPSLA Track List"
threshold_down = 11
threshold_up = 12
type = "weight"
members {
destination_ip = "1.1.1.1"
ipsla_monitoring_policy_uuid = mso_tenant_policies_ipsla_monitoring_policy.ipsla_monitoring_policy.uuid
scope_type = "bd"
scope_uuid = mso_schema_template_bd.example_bd.uuid
}
}
96 changes: 96 additions & 0 deletions mso/datasource_mso_tenant_policies_ipsla_track_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package mso

import (
"fmt"
"log"

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

func datasourceMSOIPSLATrackList() *schema.Resource {
return &schema.Resource{
Read: dataSourceMSOIPSLATrackListRead,

Schema: map[string]*schema.Schema{
"template_id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"uuid": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"threshold_up": {
Type: schema.TypeInt,
Computed: true,
},
"threshold_down": {
Type: schema.TypeInt,
Computed: true,
},
"members": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"destination_ip": {
Type: schema.TypeString,
Computed: true,
},
"ipsla_monitoring_policy_uuid": {
Type: schema.TypeString,
Computed: true,
},
"scope_type": {
Type: schema.TypeString,
Computed: true,
},
"scope_uuid": {
Type: schema.TypeString,
Computed: true,
},
"weight": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
}
}

func dataSourceMSOIPSLATrackListRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[DEBUG] MSO IPSLA Track List 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", "ipslaTrackLists")
if err != nil {
return err
}

setIPSLATrackListData(d, policy, templateId)
log.Printf("[DEBUG] MSO IPSLA Track List Data Source - Read Complete : %v", d.Id())
return nil
}
46 changes: 46 additions & 0 deletions mso/datasource_mso_tenant_policies_ipsla_track_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package mso

import (
"fmt"
"testing"

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

func TestAccMSOTenantPoliciesIPSLATrackListDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: IPSLA Track List Data Source") },
Config: testAccMSOTenantPoliciesIPSLATrackListDataSource(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_track_list."+msoTenantPolicyTemplateIPSLATrackListName+"_data", "name", msoTenantPolicyTemplateIPSLATrackListName),
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_track_list."+msoTenantPolicyTemplateIPSLATrackListName+"_data", "description", "Terraform test IPSLA Track List"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_track_list."+msoTenantPolicyTemplateIPSLATrackListName+"_data", "threshold_down", "11"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_track_list."+msoTenantPolicyTemplateIPSLATrackListName+"_data", "threshold_up", "12"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_track_list."+msoTenantPolicyTemplateIPSLATrackListName+"_data", "type", "percentage"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_track_list."+msoTenantPolicyTemplateIPSLATrackListName+"_data", "members.#", "1"),
customTestCheckResourceTypeSetAttr("data.mso_tenant_policies_ipsla_track_list."+msoTenantPolicyTemplateIPSLATrackListName+"_data", "members",
map[string]string{
"destination_ip": "1.1.1.2",
"ipsla_monitoring_policy_uuid": fmt.Sprintf("mso_tenant_policies_ipsla_monitoring_policy.%s.uuid", msoTenantPolicyTemplateIPSLAMonitoringPolicyName),
"scope_type": "bd",
"scope_uuid": fmt.Sprintf("mso_schema_template_bd.%s.uuid", msoSchemaTemplateBdName),
"weight": "10",
},
),
),
},
},
})
}

func testAccMSOTenantPoliciesIPSLATrackListDataSource() string {
return fmt.Sprintf(`%[1]s
data "mso_tenant_policies_ipsla_track_list" "%[2]s_data" {
template_id = mso_tenant_policies_ipsla_track_list.%[2]s.template_id
name = "%[2]s"
}`, testAccMSOTenantPoliciesIPSLATrackListConfigUpdateRemovingExtraEntry(), msoTenantPolicyTemplateIPSLATrackListName)
}
2 changes: 2 additions & 0 deletions mso/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func Provider() terraform.ResourceProvider {
"mso_tenant_policies_bgp_peer_prefix_policy": resourceMSOBGPPeerPrefixPolicy(),
"mso_fabric_policies_l3_domain": resourceMSOL3Domain(),
"mso_tenant_policies_custom_qos_policy": resourceMSOCustomQoSPolicy(),
"mso_tenant_policies_ipsla_track_list": resourceMSOIPSLATrackList(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -205,6 +206,7 @@ func Provider() terraform.ResourceProvider {
"mso_tenant_policies_bgp_peer_prefix_policy": datasourceMSOBGPPeerPrefixPolicy(),
"mso_fabric_policies_l3_domain": datasourceMSOL3Domain(),
"mso_tenant_policies_custom_qos_policy": datasourceMSOCustomQoSPolicy(),
"mso_tenant_policies_ipsla_track_list": datasourceMSOIPSLATrackList(),
},

ConfigureFunc: configureClient,
Expand Down
Loading
Loading