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,47 @@
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_port_channel_interface" "example" {
template_id = mso_template.fabric_resource_template.id
name = "example"
description = "example description"
node = "101"
interfaces = ["1/1", "1/2"]
interface_policy_group_uuid = mso_fabric_policies_interface_setting.port_channel_interface.id
interface_descriptions {
interface = "1/1"
description = "1/1 description"
}
interface_descriptions {
interface = "1/2"
description = "1/2 description"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package mso

import (
"fmt"
"log"

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

func datasourceMSOPortChannelInterface() *schema.Resource {
return &schema.Resource{
Read: dataSourceMSOPortChannelInterfaceRead,

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

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

err = setPortChannelInterfaceData(d, policy, templateId)
if err != nil {
return err
}

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

import (
"fmt"
"testing"

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

func TestAccMSOFabricResourcePortChannelInterfaceDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: Port Channel Interface Data Source - With Interface Descriptions") },
Config: testAccMSOFabricResourcePortChannelInterfaceDataSourceWithInterfaceDescriptions(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "name", msoFabricResourcePortChannelInterfaceName),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "description", "Terraform test Port Channel Interface updated"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "node", "101"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "interfaces.#", "2"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "uuid"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "template_id"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "interface_policy_group_uuid"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "interface_descriptions.#", "2"),
CustomTestCheckTypeSetElemAttrs("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "interface_descriptions",
map[string]string{
"interface": "1/1",
"description": "Interface Description 1/1",
},
),
CustomTestCheckTypeSetElemAttrs("data.mso_fabric_resource_policies_port_channel_interface."+msoFabricResourcePortChannelInterfaceName, "interface_descriptions",
map[string]string{
"interface": "1/2",
"description": "Interface Description 1/2",
},
),
),
},
},
})
}

func testAccMSOFabricResourcePortChannelInterfaceDataSourceWithInterfaceDescriptions() string {
return fmt.Sprintf(`%[1]s
data "mso_fabric_resource_policies_port_channel_interface" "%[2]s" {
template_id = mso_template.%[3]s.id
name = mso_fabric_resource_policies_port_channel_interface.%[2]s.name
}`,
testAccMSOFabricResourcePortChannelInterfaceConfigUpdateAddingExtraInterfaceDescription(),
msoFabricResourcePortChannelInterfaceName,
msoFabricResourceTemplateName,
)
}
Loading
Loading