Skip to content
78 changes: 78 additions & 0 deletions examples/tenant_policies_igmp_interface_policy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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
}

resource "mso_tenant_policies_route_map_policy_multicast" "state_limit" {
template_id = mso_template.tenant_template.id
name = "tf_test_state_limit"
description = "Terraform test Route Map Policy for Multicast"
route_map_multicast_entries {
order = 1
group_ip = "226.2.2.2/8"
source_ip = "1.1.1.1/1"
rendezvous_point_ip = "1.1.1.2"
action = "permit"
}
}

resource "mso_tenant_policies_route_map_policy_multicast" "report_policy" {
template_id = mso_tenant_policies_route_map_policy_multicast.state_limit.template_id
name = "tf_test_report_policy"
description = "Terraform test Route Map Policy for Multicast"
route_map_multicast_entries {
order = 1
group_ip = "226.2.2.2/8"
source_ip = "1.1.1.1/1"
rendezvous_point_ip = "1.1.1.2"
action = "permit"
}
}

resource "mso_tenant_policies_route_map_policy_multicast" "static_report" {
template_id = mso_tenant_policies_route_map_policy_multicast.report_policy.template_id
name = "tf_test_static_report"
description = "Terraform test Route Map Policy for Multicast"
route_map_multicast_entries {
order = 1
group_ip = "226.2.2.2/8"
source_ip = "1.1.1.1/1"
rendezvous_point_ip = "1.1.1.2"
action = "permit"
}
}

# tenant policies igmp interface policy example

resource "mso_tenant_policies_igmp_interface_policy" "igmp_policy" {
template_id = mso_template.tenant_template.id
name = "test_igmp_interface_policy"
description = "With Route Maps"
igmp_version = "v3"
state_limit_route_map_uuid = mso_tenant_policies_route_map_policy_multicast.state_limit.uuid
report_policy_route_map_uuid = mso_tenant_policies_route_map_policy_multicast.report_policy.uuid
static_report_route_map_uuid = mso_tenant_policies_route_map_policy_multicast.static_report.uuid
maximum_multicast_entries = 5000000
}
150 changes: 150 additions & 0 deletions mso/datasource_mso_tenant_policies_igmp_interface_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package mso

import (
"fmt"
"log"

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

func datasourceMSOIGMPInterfacePolicy() *schema.Resource {
return &schema.Resource{
Read: dataSourceMSOIGMPInterfacePolicyRead,

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 IGMP Interface Policy.",
},
"uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of the IGMP Interface Policy.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the IGMP Interface Policy.",
},
"version3_asm": {
Type: schema.TypeBool,
Computed: true,
Description: "Enable or disable IGMP version 3 ASM.",
},
"fast_leave": {
Type: schema.TypeBool,
Computed: true,
Description: "Enable or disable fast leave.",
},
"report_link_local_groups": {
Type: schema.TypeBool,
Computed: true,
Description: "Enable or disable reporting link-local groups.",
},
"igmp_version": {
Type: schema.TypeString,
Computed: true,
Description: "The IGMP version (v2 or v3).",
},
"group_timeout": {
Type: schema.TypeInt,
Computed: true,
Description: "The group timeout value in seconds.",
},
"query_interval": {
Type: schema.TypeInt,
Computed: true,
Description: "The query interval value in seconds.",
},
"query_response_interval": {
Type: schema.TypeInt,
Computed: true,
Description: "The query response interval value in seconds.",
},
"last_member_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The last member query count value.",
},
"last_member_response_time": {
Type: schema.TypeInt,
Computed: true,
Description: "The last member query response time value in seconds.",
},
"startup_query_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The startup query count value.",
},
"startup_query_interval": {
Type: schema.TypeInt,
Computed: true,
Description: "The startup query interval value in seconds.",
},
"querier_timeout": {
Type: schema.TypeInt,
Computed: true,
Description: "The querier timeout value in seconds.",
},
"robustness_variable": {
Type: schema.TypeInt,
Computed: true,
Description: "The robustness variable value.",
},
"state_limit_route_map_uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of the state limit route map policy for multicast.",
},
"report_policy_route_map_uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of the report policy route map for multicast.",
},
"static_report_route_map_uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of the static report route map for multicast.",
},
"maximum_multicast_entries": {
Type: schema.TypeInt,
Computed: true,
Description: "The maximum multicast entries value.",
},
"reserved_multicast_entries": {
Type: schema.TypeInt,
Computed: true,
Description: "The reserved multicast entries value.",
},
},
}
}

func dataSourceMSOIGMPInterfacePolicyRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[DEBUG] MSO IGMP Interface 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", "igmpInterfacePolicies")
if err != nil {
return err
}

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

import (
"fmt"
"testing"

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

func TestAccMSOTenantPoliciesIGMPInterfacePolicyDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: IGMP Interface Policy Data Source") },
Config: testAccMSOTenantPoliciesIGMPInterfacePolicyDataSource(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "name", "test_igmp_interface_policy_max"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "description", "Maximum Values Test"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "uuid"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "template_id"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "version3_asm", "true"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "fast_leave", "true"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "report_link_local_groups", "true"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "igmp_version", "v3"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "group_timeout", "65535"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "query_interval", "18000"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "query_response_interval", "25"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "last_member_count", "5"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "last_member_response_time", "25"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "startup_query_count", "10"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "startup_query_interval", "18000"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "querier_timeout", "65535"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "robustness_variable", "7"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "maximum_multicast_entries", "4294967295"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "reserved_multicast_entries", "4294967295"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_igmp_interface_policy.igmp_policy", "static_report_route_map_uuid"),
),
},
},
})
}

func testAccMSOTenantPoliciesIGMPInterfacePolicyDataSource() string {
return fmt.Sprintf(`%s
resource "mso_tenant_policies_route_map_policy_multicast" "static_report" {
template_id = mso_template.template_tenant.id
name = "test_static_report_route_map"
description = "Static Report Route Map for IGMP"
route_map_multicast_entries {
order = 1
group_ip = "226.2.2.2/8"
source_ip = "1.1.1.1/1"
rendezvous_point_ip = "1.1.1.2"
action = "permit"
}
}

resource "mso_tenant_policies_igmp_interface_policy" "igmp_policy" {
template_id = mso_template.template_tenant.id
name = "test_igmp_interface_policy_max"
description = "Maximum Values Test"
version3_asm = true
fast_leave = true
report_link_local_groups = true
igmp_version = "v3"
group_timeout = 65535
query_interval = 18000
query_response_interval = 25
last_member_count = 5
last_member_response_time = 25
startup_query_count = 10
startup_query_interval = 18000
querier_timeout = 65535
robustness_variable = 7
maximum_multicast_entries = 4294967295
reserved_multicast_entries = 4294967295
static_report_route_map_uuid = mso_tenant_policies_route_map_policy_multicast.static_report.uuid
}

data "mso_tenant_policies_igmp_interface_policy" "igmp_policy" {
template_id = mso_template.template_tenant.id
name = mso_tenant_policies_igmp_interface_policy.igmp_policy.name
}`, testAccMSOTemplateResourceTenantConfig())
}
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_igmp_interface_policy": resourceMSOIGMPInterfacePolicy(),
},

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_igmp_interface_policy": datasourceMSOIGMPInterfacePolicy(),
},

ConfigureFunc: configureClient,
Expand Down
Loading
Loading