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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
terraform {
required_providers {
mso = {
source = "CiscoDevNet/mso"
}
}
}

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

resource "mso_template" "fabric_policy_template" {
template_name = "fabric_policy_template"
template_type = "fabric_policy"
}

resource "mso_fabric_policies_interface_setting" "port_channel_interface" {
template_id = mso_template.fabric_policy_template.id
type = "portchannel"
name = "port_channel_interface"
}

resource "mso_template" "fabric_resource_template" {
template_name = "fabric_resource_template"
template_type = "fabric_resource"
}

resource "mso_fabric_resource_policies_virtual_port_channel_interface" "vpc_if" {
template_id = mso_template.fabric_resource_template.id
name = "tf_vpc_if"
description = "Example VPC Interface"
node_1 = "101"
node_2 = "102"
node_1_interfaces = ["1/1", "1/10-11"]
node_2_interfaces = ["1/2"]
interface_policy_group_uuid = mso_fabric_policies_interface_setting.port_channel_interface.uuid
interface_descriptions {
node = "101"
interface = "1/1"
description = "Interface Description 1/1"
}
interface_descriptions {
node = "102"
interface = "1/10"
description = "Interface Description 1/10"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package mso

import (
"log"

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

func dataSourceMSOVirtualPortChannelInterface() *schema.Resource {
return &schema.Resource{
Read: dataSourceMSOFabricResourcePoliciesVirtualPortChannelInterfaceRead,

SchemaVersion: version,

Schema: map[string]*schema.Schema{
"template_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "Fabric Resource template ID.",
},
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "Virtual Port Channel Interface name.",
},
"uuid": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},

"node_1": {Type: schema.TypeString, Computed: true},
"node_2": {Type: schema.TypeString, Computed: true},

"node_1_interfaces": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"node_2_interfaces": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"interface_policy_group_uuid": {Type: schema.TypeString, Computed: true},

"interface_descriptions": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"node": {Type: schema.TypeString, Computed: true},
"interface": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
},
},
},
},
}
}

func dataSourceMSOFabricResourcePoliciesVirtualPortChannelInterfaceRead(d *schema.ResourceData, m any) error {
log.Printf("[DEBUG] MSO VPC Interface Data Source - Beginning Read: %v", d.Id())
msoClient := m.(*client.Client)

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

err := setVPCInterfaceData(d, msoClient, templateId, name)
if err != nil {
return err
}

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

import (
"fmt"
"testing"

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

func TestAccMSOVirtualPortChannelInterfaceDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: VPC Interface Data Source") },
Config: testAccMSOVirtualPortChannelInterfaceDataSource(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "name", "tf_test_vpc_if"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "description", "Terraform test VPC Interface"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "node_1", "101"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "node_2", "102"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "node_1_interfaces.#", "2"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "node_1_interfaces.1", "1/1"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "node_1_interfaces.0", "1/10-11"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "node_2_interfaces.#", "1"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "node_2_interfaces.0", "1/2"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "interface_descriptions.#", "1"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "uuid"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if", "interface_policy_group_uuid"),
customTestCheckResourceTypeSetAttr(
"data.mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if",
"interface_descriptions",
map[string]string{
"node": "101",
"interface": "1/1",
"description": "Terraform test interface description",
},
),
),
},
},
})
}

func testAccMSOVirtualPortChannelInterfaceDataSource() string {
return fmt.Sprintf(`%s
data "mso_fabric_resource_policies_virtual_port_channel_interface" "vpc_if" {
template_id = mso_fabric_resource_policies_virtual_port_channel_interface.vpc_if.template_id
name = "tf_test_vpc_if"
}
`, testAccMSOVirtualPortChannelInterfaceConfigCreate())
}
Loading
Loading