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
64 changes: 64 additions & 0 deletions examples/fabric_resource_policies_physical_interface/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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" "physical_interface" {
template_id = mso_template.fabric_policy_template.id
type = "physical"
name = "physical_interface"
}

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

resource "mso_fabric_resource_policies_physical_interface" "physical" {
template_id = mso_template.fabric_resource_template.id
name = "physical_interface"
description = "Terraform test Physical Interface"
nodes = ["101", "102"]
interfaces = ["1/1", "1/2"]
interface_policy_group_uuid = mso_fabric_policies_interface_setting.physical_interface.id
interface_descriptions {
interface = "1/1"
description = "Interface Description 1/1"
}
interface_descriptions {
interface = "1/2"
description = "Interface Description 1/2"
}
}

resource "mso_fabric_resource_policies_physical_interface" "breakout" {
template_id = mso_template.fabric_resource_template.id
name = "breakout_mode_physical_interface"
description = "Terraform test Physical Interface with breakout mode"
nodes = ["101", "102"]
interfaces = ["1/1", "1/2"]
breakout_mode = "4x100G"
interface_descriptions {
interface = "1/1"
description = "Interface Description 1/1"
}
interface_descriptions {
interface = "1/2"
description = "Interface Description 1/2"
}
}
102 changes: 102 additions & 0 deletions mso/datasource_mso_fabric_resource_policies_physical_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package mso

import (
"fmt"
"log"

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

func datasourceMSOPhysicalInterface() *schema.Resource {
return &schema.Resource{
Read: dataSourceMSOPhysicalInterfaceRead,

Schema: map[string]*schema.Schema{
"template_id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"nodes": {
Type: schema.TypeList,
Elem: &schema.Schema{
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,
},
"breakout_mode": {
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,
},
"policy_group_type": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

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

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

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

import (
"fmt"
"testing"

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

func TestAccMSOFabricResourcePhysicalInterfaceDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: Physical Interface Data Source - With Interface type physical") },
Config: testAccMSOFabricResourcePhysicalInterfaceTypePhysicalDataSource(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "name", msoFabricResourcePhysicalInterfaceName),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "policy_group_type", "physical"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "description", "Terraform test Physical Interface updated"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "nodes.#", "2"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "interfaces.#", "2"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "uuid"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "template_id"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "interface_policy_group_uuid"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "interface_descriptions.#", "2"),
CustomTestCheckTypeSetElemAttrs("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "interface_descriptions",
map[string]string{
"interface": "1/1",
"description": "Interface Description 1/1",
},
),
CustomTestCheckTypeSetElemAttrs("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName, "interface_descriptions",
map[string]string{
"interface": "1/2",
"description": "Interface Description 1/2",
},
),
),
},
{
PreConfig: func() { fmt.Println("Test: Physical Interface Data Source - Breakout Mode setup") },
Config: testAccMSOFabricResourcePhysicalInterfaceBreakoutModeConfigUpdateRemovingExtraInterfaceDescription(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "name", msoFabricResourcePhysicalInterfaceName+"_breakout_updated"),
resource.TestCheckResourceAttr("mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "policy_group_type", "breakout"),
),
},
{
PreConfig: func() { fmt.Println("Test: Physical Interface Data Source - Breakout Mode") },
Config: testAccMSOFabricResourcePhysicalInterfaceTypeBreakoutDataSource(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "name", msoFabricResourcePhysicalInterfaceName+"_breakout_updated"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "policy_group_type", "breakout"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "uuid"),
resource.TestCheckResourceAttrSet("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "template_id"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "breakout_mode", "4x100G"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "description", "Terraform test Physical Interface updated"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "nodes.#", "1"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "interfaces.#", "2"),
resource.TestCheckResourceAttr("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "interface_descriptions.#", "1"),
CustomTestCheckTypeSetElemAttrs("data.mso_fabric_resource_policies_physical_interface."+msoFabricResourcePhysicalInterfaceName+"_breakout", "interface_descriptions",
map[string]string{
"interface": "1/2",
"description": "Interface Description 1/2",
},
),
),
},
},
})
}

func testAccMSOFabricResourcePhysicalInterfaceTypePhysicalDataSource() string {
return fmt.Sprintf(`%[1]s
data "mso_fabric_resource_policies_physical_interface" "%[2]s" {
template_id = mso_template.%[3]s.id
name = mso_fabric_resource_policies_physical_interface.%[2]s.name
}`,
testAccMSOFabricResourcePhysicalInterfaceConfigUpdateAddingExtraInterfaceDescription(),
msoFabricResourcePhysicalInterfaceName,
msoFabricResourceTemplateName,
)
}

func testAccMSOFabricResourcePhysicalInterfaceTypeBreakoutDataSource() string {
return fmt.Sprintf(`%[1]s
data "mso_fabric_resource_policies_physical_interface" "%[2]s" {
template_id = mso_template.%[3]s.id
name = mso_fabric_resource_policies_physical_interface.%[2]s.name
}`,
testAccMSOFabricResourcePhysicalInterfaceBreakoutModeConfigUpdateRemovingExtraInterfaceDescription(),
msoFabricResourcePhysicalInterfaceName+"_breakout",
msoFabricResourceTemplateName,
)
}
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_fabric_resource_policies_physical_interface": resourceMSOPhysicalInterface(),
},

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_fabric_resource_policies_physical_interface": datasourceMSOPhysicalInterface(),
},

ConfigureFunc: configureClient,
Expand Down
Loading
Loading