-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[minor_change] Addition of new resource and data source for mso_tenan…
…t_policies_ipsla_monitoring_policy
- Loading branch information
Showing
11 changed files
with
940 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
terraform { | ||
required_providers { | ||
mso = { | ||
source = "CiscoDevNet/mso" | ||
} | ||
} | ||
} | ||
|
||
provider "mso" { | ||
username = "" # <MSO username> | ||
password = "" # <MSO pwd> | ||
url = "" # <MSO URL> | ||
insecure = true | ||
} | ||
|
||
data "mso_site" "site_1" { | ||
name = "example_site_1" | ||
} | ||
|
||
data "mso_site" "site_2" { | ||
name = "example_site_2" | ||
} | ||
|
||
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 | ||
sites = [data.mso_site.site_1.id, data.mso_site.site_2.id] | ||
} | ||
|
||
# tenant policies ipsla monitoring policy example | ||
|
||
resource "mso_tenant_policies_ipsla_monitoring_policy" "ipsla_policy" { | ||
template_id = mso_template.tenant_template.id | ||
name = "ipsla_policy" | ||
description = "Example description" | ||
sla_type = "http" | ||
http_version = "HTTP11" | ||
http_uri = "/example1" | ||
sla_frequency = 120 | ||
detect_multiplier = 4 | ||
request_data_size = 64 | ||
type_of_service = 18 | ||
operation_timeout = 100 | ||
threshold = 100 | ||
ipv6_traffic_class = 255 | ||
} |
100 changes: 100 additions & 0 deletions
100
mso/datasource_mso_tenant_policies_ipsla_monitoring_policy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package mso | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/ciscoecosystem/mso-go-client/client" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func datasourceMSOIPSLAMonitoringPolicy() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceMSOIPSLAMonitoringPolicyRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"template_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"uuid": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sla_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"destination_port": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"http_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"http_uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sla_frequency": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"detect_multiplier": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"request_data_size": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"type_of_service": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"operation_timeout": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"threshold": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"ipv6_traffic_class": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMSOIPSLAMonitoringPolicyRead(d *schema.ResourceData, m interface{}) error { | ||
log.Printf("[DEBUG] MSO IPSLA Monitoring 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", "ipslaMonitoringPolicies") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
setIPSLAMonitoringPolicyData(d, policy, templateId) | ||
log.Printf("[DEBUG] MSO IPSLA Monitoring Policy Data Source - Read Complete : %v", d.Id()) | ||
return nil | ||
} |
44 changes: 44 additions & 0 deletions
44
mso/datasource_mso_tenant_policies_ipsla_monitoring_policy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package mso | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccMSOTenantPoliciesIPSLAMonitoringPolicyDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
PreConfig: func() { fmt.Println("Test: IPSLA Monitoring Policy Data Source") }, | ||
Config: testAccMSOTenantPoliciesIPSLAMonitoringPolicyDataSource(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "name", "test_ipsla_policy"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "description", "HTTP Type"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "sla_type", "http"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "destination_port", "80"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "http_version", "HTTP11"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "http_uri", "/example"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "sla_frequency", "120"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "detect_multiplier", "4"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "request_data_size", "64"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "type_of_service", "18"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "operation_timeout", "100"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "threshold", "100"), | ||
resource.TestCheckResourceAttr("data.mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy", "ipv6_traffic_class", "255"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccMSOTenantPoliciesIPSLAMonitoringPolicyDataSource() string { | ||
return fmt.Sprintf(`%s | ||
data "mso_tenant_policies_ipsla_monitoring_policy" "ipsla_policy" { | ||
template_id = mso_tenant_policies_ipsla_monitoring_policy.ipsla_policy.template_id | ||
name = "test_ipsla_policy" | ||
}`, testAccMSOTenantPoliciesIPSLAMonitoringPolicyConfigCreate()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.