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

# NetFlow Exporter example

resource "mso_tenant_policies_netflow_exporter" "netflow_exporter" {
template_id = mso_template.tenant_template.id
name = "netflow_exporter_1"
}

# NetFlow Exporter data source example

data "mso_tenant_policies_netflow_exporter" "netflow_exporter" {
template_id = mso_template.tenant_template.id
name = mso_tenant_policies_netflow_exporter.netflow_exporter.name
}
57 changes: 57 additions & 0 deletions examples/tenant_policies_netflow_monitor/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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
}

# NetFlow Exporter example

resource "mso_tenant_policies_netflow_exporter" "netflow_exporter" {
template_id = mso_template.tenant_template.id
name = "netflow_exporter_1"
}

# NetFlow Record example

resource "mso_tenant_policies_netflow_record" "netflow_record" {
template_id = mso_template.tenant_template.id
name = "netflow_record_1"
}

# NetFlow Monitor example

resource "mso_tenant_policies_netflow_monitor" "netflow_monitor" {
template_id = mso_template.tenant_template.id
name = "netflow_monitor_1"
description = "Test NetFlow Monitor"
netflow_record_uuid = mso_tenant_policies_netflow_record.netflow_record.uuid
netflow_exporter_uuids = [mso_tenant_policies_netflow_exporter.netflow_exporter.uuid]
}

# NetFlow Monitor data source example

data "mso_tenant_policies_netflow_monitor" "netflow_monitor" {
template_id = mso_template.tenant_template.id
name = mso_tenant_policies_netflow_monitor.netflow_monitor.name
}
42 changes: 42 additions & 0 deletions examples/tenant_policies_netflow_record/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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
}

# NetFlow Record example

resource "mso_tenant_policies_netflow_record" "netflow_record" {
template_id = mso_template.tenant_template.id
name = "netflow_record_1"
description = "My NetFlow Record"
match_parameters = ["destination_ip", "source_ip", "ip_protocol"]
}

# NetFlow Record data source example

data "mso_tenant_policies_netflow_record" "netflow_record" {
template_id = mso_template.tenant_template.id
name = mso_tenant_policies_netflow_record.netflow_record.name
}
26 changes: 26 additions & 0 deletions mso/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ var targetDscpMap = map[string]string{
"voiceAdmit": "voice_admit",
}

var matchParameterMap = map[string]string{
"destination_ip": "dstIP",
"destination_ipv4": "dstIPv4",
"destination_ipv6": "dstIPv6",
"destination_mac": "dstMac",
"destination_port": "dstPort",
"ethertype": "ethertype",
"ip_protocol": "proto",
"source_ip": "srcIP",
"source_ipv4": "srcIPv4",
"source_ipv6": "srcIPv6",
"source_mac": "srcMac",
"source_port": "srcPort",
"dstIP": "destination_ip",
"dstIPv4": "destination_ipv4",
"dstIPv6": "destination_ipv6",
"dstMac": "destination_mac",
"dstPort": "destination_port",
"proto": "ip_protocol",
"srcIP": "source_ip",
"srcIPv4": "source_ipv4",
"srcIPv6": "source_ipv6",
"srcMac": "source_mac",
"srcPort": "source_port",
}

var enabledDisabledMap = map[interface{}]interface{}{
"enabled": true,
"disabled": false,
Expand Down
58 changes: 58 additions & 0 deletions mso/datasource_mso_tenant_policies_netflow_exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package mso

import (
"fmt"
"log"

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

func datasourceMSONetflowExporter() *schema.Resource {
return &schema.Resource{
Read: dataSourceMSONetflowExporterRead,

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 NetFlow Exporter.",
},
"uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of the NetFlow Exporter.",
},
},
}
}

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

err = setNetflowExporterData(d, policy, templateId)
if err != nil {
return err
}
log.Printf("[DEBUG] MSO NetFlow Exporter Data Source - Read Complete: %v", d.Id())
return nil
}
33 changes: 33 additions & 0 deletions mso/datasource_mso_tenant_policies_netflow_exporter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mso

import (
"fmt"
"testing"

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

func TestAccMSOTenantPoliciesNetflowExporterDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: NetFlow Exporter Data Source") },
Config: testAccMSOTenantPoliciesNetflowExporterDataSource(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_tenant_policies_netflow_exporter.netflow_exporter", "name", "test_netflow_exporter"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_netflow_exporter.netflow_exporter", "uuid"),
),
},
},
})
}

func testAccMSOTenantPoliciesNetflowExporterDataSource() string {
return fmt.Sprintf(`%s
data "mso_tenant_policies_netflow_exporter" "netflow_exporter" {
template_id = mso_tenant_policies_netflow_exporter.netflow_exporter.template_id
name = "test_netflow_exporter"
}`, testAccMSOTenantPoliciesNetflowExporterConfigCreate())
}
74 changes: 74 additions & 0 deletions mso/datasource_mso_tenant_policies_netflow_monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package mso

import (
"fmt"
"log"

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

func datasourceMSOTenantPoliciesNetflowMonitor() *schema.Resource {
return &schema.Resource{
Read: dataSourceMSOTenantPoliciesNetflowMonitorRead,

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 NetFlow Monitor.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the NetFlow Monitor.",
},
"uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of the NetFlow Monitor.",
},
"netflow_record_uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of the NetFlow Record.",
},
"netflow_exporter_uuids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "The list of NetFlow Exporter UUIDs.",
},
},
}
}

func dataSourceMSOTenantPoliciesNetflowMonitorRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[DEBUG] MSO NetFlow Monitor Data Source - Beginning Read")
msoClient := m.(*client.Client)

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

response, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/templates/%s", templateId))
if err != nil {
return err
}

monitor, err := GetPolicyByName(response, monitorName, "tenantPolicyTemplate", "template", "netFlowMonitors")
if err != nil {
return err
}

err = setNetflowMonitorData(d, monitor, templateId)
if err != nil {
return err
}
log.Printf("[DEBUG] MSO NetFlow Monitor Data Source - Read Complete: %v", d.Id())
return nil
}
36 changes: 36 additions & 0 deletions mso/datasource_mso_tenant_policies_netflow_monitor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package mso

import (
"fmt"
"testing"

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

func TestAccMSOTenantPoliciesNetflowMonitorDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: NetFlow Monitor Data Source") },
Config: testAccMSOTenantPoliciesNetflowMonitorDataSource(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.mso_tenant_policies_netflow_monitor.netflow_monitor", "name", "test_netflow_monitor"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_netflow_monitor.netflow_monitor", "uuid"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_netflow_monitor.netflow_monitor", "netflow_record_uuid"),
resource.TestCheckResourceAttr("data.mso_tenant_policies_netflow_monitor.netflow_monitor", "netflow_exporter_uuids.#", "1"),
resource.TestCheckResourceAttrSet("data.mso_tenant_policies_netflow_monitor.netflow_monitor", "netflow_exporter_uuids.0"),
),
},
},
})
}

func testAccMSOTenantPoliciesNetflowMonitorDataSource() string {
return fmt.Sprintf(`%s
data "mso_tenant_policies_netflow_monitor" "netflow_monitor" {
template_id = mso_tenant_policies_netflow_monitor.netflow_monitor.template_id
name = "test_netflow_monitor"
}`, testAccMSOTenantPoliciesNetflowMonitorConfigCreate())
}
Loading
Loading