From 381927b9306f4b1cca2ba60bd613c9aacf93266a Mon Sep 17 00:00:00 2001 From: samitab Date: Mon, 16 Feb 2026 19:03:33 +1000 Subject: [PATCH 1/8] [minor_change] Add mso_fabric_policies_ptp_policy resource and datasource. --- examples/fabric_policies_ptp_policy/main.tf | 38 ++ ...tasource_mso_fabric_policies_ptp_policy.go | 121 +++++ ...rce_mso_fabric_policies_ptp_policy_test.go | 42 ++ mso/provider.go | 2 + ...resource_mso_fabric_policies_ptp_policy.go | 455 ++++++++++++++++++ ...rce_mso_fabric_policies_ptp_policy_test.go | 233 +++++++++ .../fabric_policies_ptp_policy.html.markdown | 54 +++ .../fabric_policies_ptp_policy.html.markdown | 64 +++ 8 files changed, 1009 insertions(+) create mode 100644 examples/fabric_policies_ptp_policy/main.tf create mode 100644 mso/datasource_mso_fabric_policies_ptp_policy.go create mode 100644 mso/datasource_mso_fabric_policies_ptp_policy_test.go create mode 100644 mso/resource_mso_fabric_policies_ptp_policy.go create mode 100644 mso/resource_mso_fabric_policies_ptp_policy_test.go create mode 100644 website/docs/d/fabric_policies_ptp_policy.html.markdown create mode 100644 website/docs/r/fabric_policies_ptp_policy.html.markdown diff --git a/examples/fabric_policies_ptp_policy/main.tf b/examples/fabric_policies_ptp_policy/main.tf new file mode 100644 index 00000000..91332631 --- /dev/null +++ b/examples/fabric_policies_ptp_policy/main.tf @@ -0,0 +1,38 @@ +terraform { + required_providers { + mso = { + source = "CiscoDevNet/mso" + } + } +} + +provider "mso" { + username = "" # + password = "" # + url = "" # + insecure = true +} + +# fabric policy template example + +resource "mso_template" "fabric_policy_template" { + template_name = "fabric_policy_template" + template_type = "fabric_policy" +} + +# fabric policies ptp policy example + +resource "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_template.fabric_policy_template.id + name = "ptp_policy" + description = "Example description" + admin_state = "enabled" + global_priority1 = 250 + global_priority2 = 100 + global_domain = 99 + fabric_profile_template = "aes67" + fabric_announce_interval = 1 + fabric_sync_interval = -3 + fabric_delay_interval = -2 + fabric_announce_timeout = 3 +} diff --git a/mso/datasource_mso_fabric_policies_ptp_policy.go b/mso/datasource_mso_fabric_policies_ptp_policy.go new file mode 100644 index 00000000..334cad3d --- /dev/null +++ b/mso/datasource_mso_fabric_policies_ptp_policy.go @@ -0,0 +1,121 @@ +package mso + +import ( + "log" + + "github.com/ciscoecosystem/mso-go-client/client" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func datasourceMSOPtpPolicy() *schema.Resource { + return &schema.Resource{ + Read: dataSourcePtpPolicyRead, + + Schema: map[string]*schema.Schema{ + "template_id": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "admin_state": { + Type: schema.TypeString, + Computed: true, + }, + "global_priority1": { + Type: schema.TypeInt, + Computed: true, + }, + "global_priority2": { + Type: schema.TypeInt, + Computed: true, + }, + "global_domain": { + Type: schema.TypeInt, + Computed: true, + }, + "fabric_profile_template": { + Type: schema.TypeString, + Computed: true, + }, + "fabric_announce_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "fabric_sync_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "fabric_delay_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "fabric_announce_timeout": { + Type: schema.TypeInt, + Computed: true, + }, + "ptp_profiles": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "profile_template": { + Type: schema.TypeString, + Computed: true, + }, + "delay_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "sync_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "announce_timeout": { + Type: schema.TypeInt, + Computed: true, + }, + "announce_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "override_node_profile": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func dataSourcePtpPolicyRead(d *schema.ResourceData, m interface{}) error { + log.Printf("[DEBUG] MSO PTP Policy Data Source - Beginning Read") + msoClient := m.(*client.Client) + + templateId := d.Get("template_id").(string) + policyName := d.Get("name").(string) + + setPtpPolicyData(d, msoClient, templateId, policyName) + log.Printf("[DEBUG] MSO PTP Policy Data Source - Read Complete : %v", d.Id()) + return nil +} diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_test.go b/mso/datasource_mso_fabric_policies_ptp_policy_test.go new file mode 100644 index 00000000..6ea06fcb --- /dev/null +++ b/mso/datasource_mso_fabric_policies_ptp_policy_test.go @@ -0,0 +1,42 @@ +package mso + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccMSOPtpPolicyDataSource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + PreConfig: func() { fmt.Println("Test: PTP Policy Data Source") }, + Config: testAccMSOPtpPolicyDataSource(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "enabled"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "default"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority1", "255"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority2", "254"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_domain", "100"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"), + ), + }, + }, + }) +} + +func testAccMSOPtpPolicyDataSource() string { + return fmt.Sprintf(`%s + data "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_fabric_policies_ptp_policy.ptp_policy.template_id + name = "tf_test_ptp_policy" + }`, testAccMSOPtpPolicyConfigCreate()) +} diff --git a/mso/provider.go b/mso/provider.go index 18d1c7ab..5e96c399 100644 --- a/mso/provider.go +++ b/mso/provider.go @@ -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_policies_ptp_policy": resourceMSOPtpPolicy(), }, DataSourcesMap: map[string]*schema.Resource{ @@ -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_policies_ptp_policy": datasourceMSOPtpPolicy(), }, ConfigureFunc: configureClient, diff --git a/mso/resource_mso_fabric_policies_ptp_policy.go b/mso/resource_mso_fabric_policies_ptp_policy.go new file mode 100644 index 00000000..6c56daaf --- /dev/null +++ b/mso/resource_mso_fabric_policies_ptp_policy.go @@ -0,0 +1,455 @@ +package mso + +import ( + "fmt" + "log" + + "github.com/ciscoecosystem/mso-go-client/client" + "github.com/ciscoecosystem/mso-go-client/container" + "github.com/ciscoecosystem/mso-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" +) + +func resourceMSOPtpPolicy() *schema.Resource { + return &schema.Resource{ + Create: resourceMSOPtpPolicyCreate, + Read: resourceMSOPtpPolicyRead, + Update: resourceMSOPtpPolicyUpdate, + Delete: resourceMSOPtpPolicyDelete, + Importer: &schema.ResourceImporter{ + State: resourceMSOPtpPolicyImport, + }, + + SchemaVersion: 1, + Schema: map[string]*schema.Schema{ + "template_id": { + Type: schema.TypeString, + ForceNew: true, + Required: true, + }, + "name": { + Type: schema.TypeString, + ForceNew: true, + Required: true, + ValidateFunc: validation.StringLenBetween(1, 64), + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "admin_state": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "enabled", "disabled", + }, false), + }, + "fabric_profile_template": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "aes67", "default", "smpte", + }, false), + }, + "global_priority1": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(0, 255), + }, + "global_priority2": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(0, 255), + }, + "global_domain": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(0, 128), + }, + "fabric_sync_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-4, 1), + }, + "fabric_delay_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-4, 5), + }, + "fabric_announce_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-3, 4), + }, + "fabric_announce_timeout": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(2, 10), + }, + "ptp_profile": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + "profile_template": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "aes67", "default", "smpte", "telecom", + }, false), + }, + "delay_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-4, 5), + }, + "sync_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-4, 1), + }, + "announce_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-3, 4), + }, + "announce_timeout": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(2, 10), + }, + "override_node_profile": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func setPtpProfiles(profileEntries *schema.Set) []map[string]any { + profileList := profileEntries.List() + profiles := make([]map[string]any, 0, 1) + + for _, val := range profileList { + ptpProfileEntry := val.(map[string]any) + template := ptpProfileEntry["profile_template"].(string) + if (template == "telecom") { + template = "telecomFullPath" + } + profile := map[string]any{ + "name": ptpProfileEntry["name"].(string), + "description": ptpProfileEntry["description"].(string), + "profileTemplate": template, + "announceIntvl": ptpProfileEntry["announce_interval"].(int), + "syncIntvl": ptpProfileEntry["sync_interval"].(int), + "delayIntvl": ptpProfileEntry["delay_interval"].(int), + "announceTimeout": ptpProfileEntry["announce_timeout"].(int), + "nodeProfileOverride": ptpProfileEntry["override_node_profile"].(bool), + // TODO Maybe more + } + profiles = append(profiles, profile) + } + + return profiles +} + +func setPtpPolicyData(d *schema.ResourceData, msoClient *client.Client, templateId, policyName string) error { + + response, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/templates/%s", templateId)) + if err != nil { + return err + } + + policy, err := GetPolicyByName(response, policyName, "fabricPolicyTemplate", "template", "ptpPolicy") + if err != nil { + return err + } + + d.SetId(fmt.Sprintf("templateId/%s/ptpPolicy/%s", templateId, models.StripQuotes(policy.S("name").String()))) + d.Set("template_id", templateId) + d.Set("name", models.StripQuotes(policy.S("name").String())) + d.Set("description", models.StripQuotes(policy.S("description").String())) + d.Set("uuid", models.StripQuotes(policy.S("global").S("uuid").String())) + + globalCont := policy.S("global") + d.Set("admin_state", models.StripQuotes(globalCont.S("adminState").String())) + d.Set("global_priority1", globalCont.S("prio1").Data().(float64)) + d.Set("global_priority2", globalCont.S("prio2").Data().(float64)) + d.Set("global_domain", globalCont.S("globalDomain").Data().(float64)) + d.Set("fabric_profile_template", models.StripQuotes(globalCont.S("fabProfileTemplate").String())) + d.Set("fabric_announce_interval", globalCont.S("fabAnnounceIntvl").Data().(float64)) + d.Set("fabric_sync_interval", globalCont.S("fabSyncIntvl").Data().(float64)) + d.Set("fabric_delay_interval", globalCont.S("fabDelayIntvl").Data().(float64)) + d.Set("fabric_announce_timeout", globalCont.S("fabAnnounceTimeout").Data().(float64)) + + count, err := policy.ArrayCount("profiles") + if err != nil { + return fmt.Errorf("unable to count the number of PTP profiles: %s", err) + } + profiles := make([]any, 0) + for i := range count { + profilesCont, err := policy.ArrayElement(i, "profiles") + if err != nil { + return fmt.Errorf("unable to parse element %d from the list of PTP profiles: %s", i, err) + } + ptpProfileEntry := make(map[string]any) + ptpProfileEntry["name"] = models.StripQuotes(profilesCont.S("name").String()) + ptpProfileEntry["description"] = models.StripQuotes(profilesCont.S("description").String()) + ptpProfileEntry["delay_interval"] = profilesCont.S("delayIntvl").Data().(float64) + ptpProfileEntry["sync_interval"] = profilesCont.S("syncIntvl").Data().(float64) + ptpProfileEntry["announce_interval"] = profilesCont.S("announceIntvl").Data().(float64) + ptpProfileEntry["announce_timeout"] = profilesCont.S("announceTimeout").Data().(float64) + template := models.StripQuotes(profilesCont.S("profileTemplate").String()) + if (template == "telecomFullPath") { + template = "telecom" + } + ptpProfileEntry["profile_template"] = template + if profilesCont.Exists("nodeProfileOverride") { + ptpProfileEntry["override_node_profile"] = profilesCont.S("nodeProfileOverride").Data().(bool) + } + profiles = append(profiles, ptpProfileEntry) + } + d.Set("ptp_profile", profiles) + + return nil +} + +func resourceMSOPtpPolicyImport(d *schema.ResourceData, m any) ([]*schema.ResourceData, error) { + log.Printf("[DEBUG] MSO PTP Policy Resource - Beginning Import: %v", d.Id()) + msoClient := m.(*client.Client) + + templateId, err := GetTemplateIdFromResourceId(d.Id()) + if err != nil { + return nil, err + } + + policyName, err := GetPolicyNameFromResourceId(d.Id(), "ptpPolicy") + if err != nil { + return nil, err + } + + setPtpPolicyData(d, msoClient, templateId, policyName) + log.Printf("[DEBUG] MSO PTP Policy Resource - Import Complete: %v", d.Id()) + return []*schema.ResourceData{d}, nil +} + +func resourceMSOPtpPolicyCreate(d *schema.ResourceData, m any) error { + log.Printf("[DEBUG] MSO PTP Policy Resource - Beginning Create: %v", d.Id()) + msoClient := m.(*client.Client) + + payload := map[string]any{} + + payload["name"] = d.Get("name").(string) + + if description, ok := d.GetOk("description"); ok { + payload["description"] = description.(string) + } + + globalParams := make(map[string]any) + + if adminState, ok := d.GetOk("admin_state"); ok { + globalParams["adminState"] = adminState.(string) + } + + if profileTemplate, ok := d.GetOk("fabric_profile_template"); ok { + globalParams["fabProfileTemplate"] = profileTemplate.(string) + } + + if prio1, ok := d.GetOk("global_priority1"); ok { + globalParams["prio1"] = prio1.(int) + } + + if prio2, ok := d.GetOk("global_priority2"); ok { + globalParams["prio2"] = prio2.(int) + } + + if globalDomain, ok := d.GetOk("global_domain"); ok { + globalParams["globalDomain"] = globalDomain.(int) + } + + if fabAnnounceIntvl, ok := d.GetOk("fabric_announce_interval"); ok { + globalParams["fabAnnounceIntvl"] = fabAnnounceIntvl.(int) + } + + if fabSyncIntvl, ok := d.GetOk("fabric_sync_interval"); ok { + globalParams["fabSyncIntvl"] = fabSyncIntvl.(int) + } + + if fabDelayIntvl, ok := d.GetOk("fabric_delay_interval"); ok { + globalParams["fabDelayIntvl"] = fabDelayIntvl.(int) + } + + if fabAnnounceTimeout, ok := d.GetOk("fabric_announce_timeout"); ok { + globalParams["fabAnnounceTimeout"] = fabAnnounceTimeout.(int) + } + + if len(globalParams) > 0 { + payload["global"] = globalParams + } + + if profileEntries, ok := d.GetOk("ptp_profile"); ok { + payload["profiles"] = setPtpProfiles(profileEntries.(*schema.Set)) + } + + payloadModel := models.GetPatchPayload("add", "/fabricPolicyTemplate/template/ptpPolicy", payload) + templateId := d.Get("template_id").(string) + + _, err := msoClient.PatchbyID(fmt.Sprintf("api/v1/templates/%s", templateId), payloadModel) + if err != nil { + return err + } + + d.SetId(fmt.Sprintf("templateId/%s/ptpPolicy/%s", templateId, d.Get("name").(string))) + log.Printf("[DEBUG] MSO PTP Policy Resource - Create Complete: %v", d.Id()) + return resourceMSOPtpPolicyRead(d, m) +} + +func resourceMSOPtpPolicyRead(d *schema.ResourceData, m any) error { + log.Printf("[DEBUG] MSO PTP Policy Resource - Beginning Read: %v", d.Id()) + msoClient := m.(*client.Client) + + templateId := d.Get("template_id").(string) + policyName := d.Get("name").(string) + + setPtpPolicyData(d, msoClient, templateId, policyName) + log.Printf("[DEBUG] MSO PTP Policy Resource - Read Complete : %v", d.Id()) + return nil +} + +func resourceMSOPtpPolicyUpdate(d *schema.ResourceData, m any) error { + log.Printf("[DEBUG] MSO PTP Policy Resource - Beginning Update: %v", d.Id()) + msoClient := m.(*client.Client) + templateId := d.Get("template_id").(string) + + updatePath := "/fabricPolicyTemplate/template/ptpPolicy" + + payloadCont := container.New() + payloadCont.Array() + + if d.HasChange("name") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/name", updatePath), d.Get("name").(string)) + if err != nil { + return err + } + } + + if d.HasChange("description") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/description", updatePath), d.Get("description").(string)) + if err != nil { + return err + } + } + + if d.HasChange("admin_state") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/adminState", updatePath), d.Get("admin_state").(string)) + if err != nil { + return err + } + } + + if d.HasChange("fabric_profile_template") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/fabProfileTemplate", updatePath), d.Get("fabric_profile_template").(string)) + if err != nil { + return err + } + } + + if d.HasChange("global_priority1") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/prio1", updatePath), d.Get("global_priority1").(int)) + if err != nil { + return err + } + } + + if d.HasChange("global_priority2") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/prio2", updatePath), d.Get("global_priority2").(int)) + if err != nil { + return err + } + } + + if d.HasChange("global_domain") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/globalDomain", updatePath), d.Get("global_domain").(int)) + if err != nil { + return err + } + } + + if d.HasChange("fabric_announce_interval") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/fabAnnounceIntvl", updatePath), d.Get("fabric_announce_interval").(int)) + if err != nil { + return err + } + } + + if d.HasChange("fabric_sync_interval") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/fabSyncIntvl", updatePath), d.Get("fabric_sync_interval").(int)) + if err != nil { + return err + } + } + + if d.HasChange("fabric_delay_interval") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/fabDelayIntvl", updatePath), d.Get("fabric_delay_interval").(int)) + if err != nil { + return err + } + } + + if d.HasChange("fabric_announce_timeout") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/global/fabAnnounceTimeout", updatePath), d.Get("fabric_announce_timeout").(int)) + if err != nil { + return err + } + } + + if d.HasChange("ptp_profile") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/profiles", updatePath), setPtpProfiles(d.Get("ptp_profile").(*schema.Set))) + if err != nil { + return err + } + } + + err := doPatchRequest(msoClient, fmt.Sprintf("api/v1/templates/%s", templateId), payloadCont) + if err != nil { + return err + } + + d.SetId(fmt.Sprintf("templateId/%s/ptpPolicy/%s", templateId, d.Get("name").(string))) + log.Printf("[DEBUG] MSO PTP Policy Resource - Update Complete: %v", d.Id()) + return resourceMSOPtpPolicyRead(d, m) +} + +func resourceMSOPtpPolicyDelete(d *schema.ResourceData, m any) error { + log.Printf("[DEBUG] MSO PTP Policy Resource - Beginning Delete: %v", d.Id()) + msoClient := m.(*client.Client) + + payloadModel := models.GetRemovePatchPayload("/fabricPolicyTemplate/template/ptpPolicy") + + _, err := msoClient.PatchbyID(fmt.Sprintf("api/v1/templates/%s", d.Get("template_id").(string)), payloadModel) + if err != nil { + return err + } + + d.SetId("") + log.Printf("[DEBUG] MSO PTP Policy Resource - Delete Complete: %v", d.Id()) + return nil +} diff --git a/mso/resource_mso_fabric_policies_ptp_policy_test.go b/mso/resource_mso_fabric_policies_ptp_policy_test.go new file mode 100644 index 00000000..c8625725 --- /dev/null +++ b/mso/resource_mso_fabric_policies_ptp_policy_test.go @@ -0,0 +1,233 @@ +package mso + +import ( + "fmt" + "testing" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccMSOPtpPolicyResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + PreConfig: func() { fmt.Println("Test: Create PTP Policy") }, + Config: testAccMSOPtpPolicyConfigCreate(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "enabled"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "default"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority1", "255"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority2", "254"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_domain", "100"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile.#", "1"), + customTestCheckResourceTypeSetAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile", + map[string]string{ + "name" : "profile1", + "delay_interval" : "-2", + "profile_template" : "aes67", + "sync_interval" : "-3", + "announce_timeout" : "3", + "announce_interval" : "1", + "override_node_profile" : "false", + }, + ), + ), + }, + { + PreConfig: func() { fmt.Println("Test: Update PTP Policy disabled state") }, + Config: testAccMSOPtpPolicyConfigUpdateDisable(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy disabled"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "disabled"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "default"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority1", "255"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority2", "254"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_domain", "100"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile.#", "2"), + customTestCheckResourceTypeSetAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile", + map[string]string{ + "name" : "profile1", + "delay_interval" : "-2", + "profile_template" : "aes67", + "sync_interval" : "-3", + "announce_timeout" : "3", + "announce_interval" : "1", + "override_node_profile" : "false", + }, + ), + customTestCheckResourceTypeSetAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile", + map[string]string{ + "name" : "profile2", + "delay_interval" : "-2", + "profile_template" : "aes67", + "sync_interval" : "-3", + "announce_timeout" : "3", + "announce_interval" : "1", + "override_node_profile" : "false", + }, + ), + ), + }, + { + PreConfig: func() { fmt.Println("Test: Update PTP Policy remove one profile") }, + Config: testAccMSOPtpPolicyConfigUpdateRemoveProfile(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy disabled"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "disabled"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "default"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority1", "255"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority2", "254"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_domain", "100"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"), + ), + }, + { + PreConfig: func() { fmt.Println("Test: Update PTP Policy changing the profile template") }, + Config: testAccMSOPtpPolicyConfigUpdateChangingTemplate(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "enabled"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "smpte"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority1", "200"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority2", "250"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_domain", "99"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_interval", "-3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-4"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "-2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "10"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile.#", "0"), + ), + }, + { + PreConfig: func() { fmt.Println("Test: Import PTP Policy") }, + ResourceName: "mso_fabric_policies_ptp_policy.ptp_policy", + ImportState: true, + ImportStateVerify: true, + }, + }, + CheckDestroy: testCheckResourceDestroyPolicyWithPathAttributesAndArguments("mso_fabric_policies_ptp_policy", "fabricPolicyTemplate", "template", "ptpProfile"), + }) +} + +func testAccMSOPtpPolicyConfigCreate() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_template.template_fabric_policy.id + name = "tf_test_ptp_policy" + description = "Terraform test PTP Policy" + admin_state = "enabled" + fabric_profile_template = "default" + global_priority1 = 255 + global_priority2 = 254 + global_domain = 100 + fabric_announce_interval = 1 + fabric_sync_interval = -1 + fabric_delay_interval = 1 + fabric_announce_timeout = 3 + ptp_profile { + name = "profile1" + profile_template = "aes67" + delay_interval = -2 + sync_interval = -3 + announce_timeout = 3 + announce_interval = 1 + override_node_profile = false + } + }`, testAccMSOTemplateResourceFabricPolicyConfig()) +} + +func testAccMSOPtpPolicyConfigUpdateDisable() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_template.template_fabric_policy.id + name = "tf_test_ptp_policy" + description = "Terraform test PTP Policy disabled" + admin_state = "disabled" + fabric_profile_template = "default" + global_priority1 = 255 + global_priority2 = 254 + global_domain = 100 + fabric_announce_interval = 1 + fabric_sync_interval = -1 + fabric_delay_interval = 1 + fabric_announce_timeout = 3 + ptp_profile { + name = "profile1" + profile_template = "aes67" + delay_interval = -2 + sync_interval = -3 + announce_timeout = 3 + announce_interval = 1 + override_node_profile = false + } + ptp_profile { + name = "profile2" + profile_template = "telecom" + announce_interval = -3 + delay_interval = -4 + sync_interval = -4 + announce_timeout = 3 + } + }`, testAccMSOTemplateResourceFabricPolicyConfig()) +} + +func testAccMSOPtpPolicyConfigUpdateRemoveProfile() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_template.template_fabric_policy.id + name = "tf_test_ptp_policy" + description = "Terraform test PTP Policy disabled" + admin_state = "disabled" + fabric_profile_template = "default" + global_priority1 = 255 + global_priority2 = 254 + global_domain = 100 + fabric_announce_interval = 1 + fabric_sync_interval = -1 + fabric_delay_interval = 1 + fabric_announce_timeout = 3 + ptp_profile { + name = "profile2" + profile_template = "telecom" + announce_interval = -3 + delay_interval = -4 + sync_interval = -4 + announce_timeout = 3 + } + }`, testAccMSOTemplateResourceFabricPolicyConfig()) +} + +func testAccMSOPtpPolicyConfigUpdateChangingTemplate() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_template.template_fabric_policy.id + name = "tf_test_ptp_policy" + description = "Terraform test PTP Policy" + admin_state = "enabled" + fabric_profile_template = "smpte" + global_priority1 = 200 + global_priority2 = 250 + global_domain = 99 + fabric_announce_interval = -3 + fabric_sync_interval = -4 + fabric_delay_interval = -2 + fabric_announce_timeout = 10 + }`, testAccMSOTemplateResourceFabricPolicyConfig()) +} diff --git a/website/docs/d/fabric_policies_ptp_policy.html.markdown b/website/docs/d/fabric_policies_ptp_policy.html.markdown new file mode 100644 index 00000000..512ee7d6 --- /dev/null +++ b/website/docs/d/fabric_policies_ptp_policy.html.markdown @@ -0,0 +1,54 @@ +--- +layout: "mso" +page_title: "MSO: mso_fabric_policies_ptp_policy" +sidebar_current: "docs-mso-data-source-fabric_policies_ptp_policy" +description: |- + Data source for the PTP Policy on Cisco Nexus Dashboard Orchestrator (NDO) +--- + +# mso_fabric_policies_ptp_policy # + +Data source for the (Precision Time Protocol) PTP Policy on Cisco Nexus Dashboard Orchestrator (NDO). This data source is supported in NDO v4.3(1) or higher. + +## GUI Information ## + +* `Location` - Manage -> Fabric Template -> Fabric Policies -> PTP Policy + +## Example Usage ## + +```hcl +data "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_template.fabric_policy_template.id + name = "ptp_policy" +} +``` + +## Argument Reference ## + +* `template_id` - (Required) The unique ID of the Fabric Policy template. +* `name` - (Required) The name of the PTP Policy. + +## Attribute Reference ## + +* `uuid` - (Read-Only) The NDO UUID of the PTP Policy. +* `id` - (Read-Only) The unique Terraform identifier of the PTP Policy. +* `description` - (Read-Only) The description of the PTP Policy. +* `admin_state` - (Read-Only) The administrative state of the PTP Policy. +* `global_priority1` - (Read-Only) The global priority1 of the PTP Policy. +* `global_priority2` - (Read-Only) The global priority2 of the PTP Policy. +* `global_domain` - (Read-Only) The global domain of the PTP Policy. +* `fabric_profile_template` - (Read-Only) The fabric profile template of the PTP Policy. +* `fabric_announce_interval` - (Read-Only) The fabric announce interval of the PTP Policy. +* `fabric_sync_interval` - (Read-Only) The fabric sync interval of the PTP Policy. +* `fabric_delay_interval` - (Read-Only) The fabric delay interval of the PTP Policy. +* `fabric_announce_timeout` - (Read-Only) The fabric announce timeout of the PTP Policy. +* `ptp_profiles` - (Read-Only) The list of PTP Profiles. + * `name` - (Read-Only) The name of the PTP Profile. + * `uuid` - (Read-Only) The NDO UUID of the PTP Profile. + * `description` - (Read-Only) The description of the PTP Profile. + * `delay_interval` - (Read-Only) The delay interval of the PTP Profile. + * `profile_template` - (Read-Only) The profile template of the PTP Profile. + * `sync_interval` - (Read-Only) The sync interval of the PTP Profile. + * `override_node_profile` - (Read-Only) The node profile override of the PTP Profile. + * `announce_timeout` - (Read-Only) The announce timeout of the PTP Profile. + * `announce_interval` - (Read-Only) The announce interval of the PTP Profile. diff --git a/website/docs/r/fabric_policies_ptp_policy.html.markdown b/website/docs/r/fabric_policies_ptp_policy.html.markdown new file mode 100644 index 00000000..57011770 --- /dev/null +++ b/website/docs/r/fabric_policies_ptp_policy.html.markdown @@ -0,0 +1,64 @@ +--- +layout: "mso" +page_title: "MSO: mso_fabric_policies_ptp_policy" +sidebar_current: "docs-mso-resource-fabric_policies_ptp_policy" +description: |- + Manages PTP Policies on Cisco Nexus Dashboard Orchestrator (NDO) +--- + +# mso_fabric_policies_ptp_policy # + +Manages PTP Policies on Cisco Nexus Dashboard Orchestrator (NDO). This resource is supported in NDO v4.3(1) or higher. + +## GUI Information ## + +* `Location` - Manage -> Fabric Template -> Fabric Policies -> PTP Policy + +## Example Usage ## + +```hcl +resource "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_template.fabric_policy_template.id + name = "ptp_policy" + description = "Example description" + admin_state = "enabled" + TODO +} +``` + +## Argument Reference ## + +* `template_id` - (Required) The unique ID of the Fabric Policy template. +* `name` - (Required) The name of the PTP Policy. +* `description` - (Optional) The description of the PTP Policy. +* `admin_state` - (Required) The administrative state of the PTP Policy. Allowed values are `enabled` or `disabled`. +* `global_priority1` - (Required) The global priority1 of the PTP Policy. Valid range: 1-255. +* `global_priority2` - (Required) The global priority2 of the PTP Policy. Valid range: 1-255. +* `global_domain` - (Required) The global domain of the PTP Policy. Valid range: 0-128. +* `fabric_profile_template` - (Required) The fabric profile template of the PTP Policy. Allowed values are `default`, `aes67`, or `smpte`. +* `fabric_announce_interval` - (Required) The fabric announce interval in log base 2 seconds of the PTP Policy. Valid range: -3 to 4. +* `fabric_sync_interval` - (Required) The fabric sync interval in log base 2 seconds of the PTP Policy. Valid range: -4 to 1. +* `fabric_delay_interval` - (Required) The fabric delay interval in log base 2 seconds of the PTP Policy. Valid range: -4 to 5. +* `fabric_announce_timeout` - (Required) The fabric announce interval timeout count of the PTP Policy. Valid range: 2 to 10. +* `ptp_profiles` - (Optional) The list of PTP Profiles. + * `name` - (Required) The name of the PTP Profile. + * `description` - (Optional) The description of the PTP Profile. + * `delay_interval` - (Required) The minimum delay request interval in log base 2 seconds of the PTP Profile. Valid range: -4 to 5. + * `profile_template` - (Required) The profile template of the PTP Profile. Allowed values are `default`, `aes67`, `smpte` or `telecom`. + * `sync_interval` - (Required) The sync interval in log base 2 seconds of the PTP Profile.Valid range: -4 to 1. + * `override_node_profile` - (Optional) The node profile override of the PTP Profile. Allowed Values: `true` or `false`. + * `announce_timeout` - (Required) The announce interval timeout count of the PTP Profile. Valid range: 2 to 10. + * `announce_interval` - (Required) The announce interval in log base 2 seconds of the PTP Profile. Valid range: -3 to 4. + +## Attribute Reference ## + +* `uuid` - (Read-Only) The NDO UUID of the PTP Policy. +* `id` - (Read-Only) The unique Terraform identifier of the PTP Policy. + +## Importing ## + +An existing MSO PTP Policy can be [imported][docs-import] into this resource via its ID/path, via the following command: [docs-import]: + +```bash +terraform import mso_fabric_policies_ptp_policy.ptp_policy templateId/{template_id}/ptpPolicy/{name} +``` From 5aac1248c6fe08a55a57080c89340fcb6d87018b Mon Sep 17 00:00:00 2001 From: samitab Date: Wed, 18 Feb 2026 14:41:12 +1000 Subject: [PATCH 2/8] [minor_change] Add mso_fabric_policies_ptp_policy_profile resource and datasource. --- .../main.tf | 52 +++ ...tasource_mso_fabric_policies_ptp_policy.go | 40 --- ..._mso_fabric_policies_ptp_policy_profile.go | 69 ++++ ...fabric_policies_ptp_policy_profile_test.go | 40 +++ ...rce_mso_fabric_policies_ptp_policy_test.go | 1 + mso/provider.go | 2 + ...resource_mso_fabric_policies_ptp_policy.go | 115 ------- ..._mso_fabric_policies_ptp_policy_profile.go | 314 ++++++++++++++++++ ...fabric_policies_ptp_policy_profile_test.go | 128 +++++++ ...rce_mso_fabric_policies_ptp_policy_test.go | 110 +----- .../fabric_policies_ptp_policy.html.markdown | 10 - ..._policies_ptp_policy_profile.html.markdown | 41 +++ .../fabric_policies_ptp_policy.html.markdown | 26 +- ..._policies_ptp_policy_profile.html.markdown | 56 ++++ 14 files changed, 719 insertions(+), 285 deletions(-) create mode 100644 examples/fabric_policies_ptp_policy_profile/main.tf create mode 100644 mso/datasource_mso_fabric_policies_ptp_policy_profile.go create mode 100644 mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go create mode 100644 mso/resource_mso_fabric_policies_ptp_policy_profile.go create mode 100644 mso/resource_mso_fabric_policies_ptp_policy_profile_test.go create mode 100644 website/docs/d/fabric_policies_ptp_policy_profile.html.markdown create mode 100644 website/docs/r/fabric_policies_ptp_policy_profile.html.markdown diff --git a/examples/fabric_policies_ptp_policy_profile/main.tf b/examples/fabric_policies_ptp_policy_profile/main.tf new file mode 100644 index 00000000..d2fb0bf7 --- /dev/null +++ b/examples/fabric_policies_ptp_policy_profile/main.tf @@ -0,0 +1,52 @@ +terraform { + required_providers { + mso = { + source = "CiscoDevNet/mso" + } + } +} + +provider "mso" { + username = "" # + password = "" # + url = "" # + insecure = true +} + +# fabric policy template example + +resource "mso_template" "fabric_policy_template" { + template_name = "fabric_policy_template" + template_type = "fabric_policy" +} + +# fabric policies ptp policy example + +resource "mso_fabric_policies_ptp_policy" "ptp_policy" { + template_id = mso_template.fabric_policy_template.id + name = "ptp_policy" + description = "Example description" + admin_state = "enabled" + global_priority1 = 250 + global_priority2 = 100 + global domain = 99 + fabric_profile_template = "aes67" + fabric_announce_interval = 1 + fabric_sync_interval = -3 + fabric_delay_interval = -2 + fabric_announce_timeout = 3 +} + +# fabric policies ptp policy profile example + +resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { + template_id = mso_template.fabric_policy_template.id + name = "ptp_policy_profile" + description = "Example description" + delay_interval = -2 + sync_interval = -3 + announce_timeout = 3 + announce_interval = 1 + profile_template = "aes67" + override_node_profile = false +} diff --git a/mso/datasource_mso_fabric_policies_ptp_policy.go b/mso/datasource_mso_fabric_policies_ptp_policy.go index 334cad3d..c14c257f 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy.go @@ -64,46 +64,6 @@ func datasourceMSOPtpPolicy() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "ptp_profiles": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "description": { - Type: schema.TypeString, - Computed: true, - }, - "profile_template": { - Type: schema.TypeString, - Computed: true, - }, - "delay_interval": { - Type: schema.TypeInt, - Computed: true, - }, - "sync_interval": { - Type: schema.TypeInt, - Computed: true, - }, - "announce_timeout": { - Type: schema.TypeInt, - Computed: true, - }, - "announce_interval": { - Type: schema.TypeInt, - Computed: true, - }, - "override_node_profile": { - Type: schema.TypeBool, - Computed: true, - }, - }, - }, - }, }, } } diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go new file mode 100644 index 00000000..8e2c66fb --- /dev/null +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go @@ -0,0 +1,69 @@ +package mso + +import ( + "log" + + "github.com/ciscoecosystem/mso-go-client/client" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func datasourceMSOPtpPolicyProfile() *schema.Resource { + return &schema.Resource{ + Read: dataSourcePtpPolicyProfileRead, + + Schema: map[string]*schema.Schema{ + "template_id": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "profile_template": { + Type: schema.TypeString, + Computed: true, + }, + "delay_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "sync_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "announce_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "announce_timeout": { + Type: schema.TypeInt, + Computed: true, + }, + "override_node_profile": { + Type: schema.TypeBool, + Computed: true, + }, + }, + } +} + +func dataSourcePtpPolicyProfileRead(d *schema.ResourceData, m interface{}) error { + log.Printf("[DEBUG] MSO PTP Policy Profile Data Source - Beginning Read") + msoClient := m.(*client.Client) + + templateId := d.Get("template_id").(string) + policyName := d.Get("name").(string) + + setPtpPolicyProfileData(d, msoClient, templateId, policyName) + log.Printf("[DEBUG] MSO PTP Policy Profile Data Source - Read Complete : %v", d.Id()) + return nil +} diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go new file mode 100644 index 00000000..315dfa79 --- /dev/null +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go @@ -0,0 +1,40 @@ +package mso + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccMSOPtpPolicyProfileDataSource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + PreConfig: func() { fmt.Println("Test: PTP Policy Profile Data Source") }, + Config: testAccMSOPtpPolicyProfileDataSource(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "description", "Terraform test PTP Policy Profile"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "aes67"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_timeout", "3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "override_node_profile", "false"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "uuid"), + ), + }, + }, + }) +} + +func testAccMSOPtpPolicyProfileDataSource() string { + return fmt.Sprintf(`%s + data "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { + template_id = mso_fabric_policies_ptp_policy_profile.ptp_policy_profile.template_id + name = "tf_ptp_profile" + }`, testAccMSOPtpPolicyProfileConfigCreate()) +} diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_test.go b/mso/datasource_mso_fabric_policies_ptp_policy_test.go index 6ea06fcb..54c034fe 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy_test.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy_test.go @@ -27,6 +27,7 @@ func TestAccMSOPtpPolicyDataSource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy.ptp_policy", "uuid"), ), }, }, diff --git a/mso/provider.go b/mso/provider.go index 5e96c399..3e549a2d 100644 --- a/mso/provider.go +++ b/mso/provider.go @@ -143,6 +143,7 @@ func Provider() terraform.ResourceProvider { "mso_tenant_policies_l3out_interface_routing_policy": resourceMSOL3OutInterfaceRoutingPolicy(), "mso_fabric_policies_interface_setting": resourceMSOInterfaceSetting(), "mso_fabric_policies_ptp_policy": resourceMSOPtpPolicy(), + "mso_fabric_policies_ptp_policy_profile": resourceMSOPtpPolicyProfile(), }, DataSourcesMap: map[string]*schema.Resource{ @@ -219,6 +220,7 @@ func Provider() terraform.ResourceProvider { "mso_tenant_policies_l3out_interface_routing_policy": datasourceMSOL3OutInterfaceRoutingPolicy(), "mso_fabric_policies_interface_setting": datasourceMSOInterfaceSetting(), "mso_fabric_policies_ptp_policy": datasourceMSOPtpPolicy(), + "mso_fabric_policies_ptp_policy_profile": datasourceMSOPtpPolicyProfile(), }, ConfigureFunc: configureClient, diff --git a/mso/resource_mso_fabric_policies_ptp_policy.go b/mso/resource_mso_fabric_policies_ptp_policy.go index 6c56daaf..2caee096 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy.go +++ b/mso/resource_mso_fabric_policies_ptp_policy.go @@ -92,85 +92,10 @@ func resourceMSOPtpPolicy() *schema.Resource { Required: true, ValidateFunc: validation.IntBetween(2, 10), }, - "ptp_profile": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - "description": { - Type: schema.TypeString, - Optional: true, - }, - "profile_template": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - "aes67", "default", "smpte", "telecom", - }, false), - }, - "delay_interval": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(-4, 5), - }, - "sync_interval": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(-4, 1), - }, - "announce_interval": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(-3, 4), - }, - "announce_timeout": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(2, 10), - }, - "override_node_profile": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - }, - }, - }, }, } } -func setPtpProfiles(profileEntries *schema.Set) []map[string]any { - profileList := profileEntries.List() - profiles := make([]map[string]any, 0, 1) - - for _, val := range profileList { - ptpProfileEntry := val.(map[string]any) - template := ptpProfileEntry["profile_template"].(string) - if (template == "telecom") { - template = "telecomFullPath" - } - profile := map[string]any{ - "name": ptpProfileEntry["name"].(string), - "description": ptpProfileEntry["description"].(string), - "profileTemplate": template, - "announceIntvl": ptpProfileEntry["announce_interval"].(int), - "syncIntvl": ptpProfileEntry["sync_interval"].(int), - "delayIntvl": ptpProfileEntry["delay_interval"].(int), - "announceTimeout": ptpProfileEntry["announce_timeout"].(int), - "nodeProfileOverride": ptpProfileEntry["override_node_profile"].(bool), - // TODO Maybe more - } - profiles = append(profiles, profile) - } - - return profiles -} - func setPtpPolicyData(d *schema.ResourceData, msoClient *client.Client, templateId, policyName string) error { response, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/templates/%s", templateId)) @@ -200,35 +125,6 @@ func setPtpPolicyData(d *schema.ResourceData, msoClient *client.Client, template d.Set("fabric_delay_interval", globalCont.S("fabDelayIntvl").Data().(float64)) d.Set("fabric_announce_timeout", globalCont.S("fabAnnounceTimeout").Data().(float64)) - count, err := policy.ArrayCount("profiles") - if err != nil { - return fmt.Errorf("unable to count the number of PTP profiles: %s", err) - } - profiles := make([]any, 0) - for i := range count { - profilesCont, err := policy.ArrayElement(i, "profiles") - if err != nil { - return fmt.Errorf("unable to parse element %d from the list of PTP profiles: %s", i, err) - } - ptpProfileEntry := make(map[string]any) - ptpProfileEntry["name"] = models.StripQuotes(profilesCont.S("name").String()) - ptpProfileEntry["description"] = models.StripQuotes(profilesCont.S("description").String()) - ptpProfileEntry["delay_interval"] = profilesCont.S("delayIntvl").Data().(float64) - ptpProfileEntry["sync_interval"] = profilesCont.S("syncIntvl").Data().(float64) - ptpProfileEntry["announce_interval"] = profilesCont.S("announceIntvl").Data().(float64) - ptpProfileEntry["announce_timeout"] = profilesCont.S("announceTimeout").Data().(float64) - template := models.StripQuotes(profilesCont.S("profileTemplate").String()) - if (template == "telecomFullPath") { - template = "telecom" - } - ptpProfileEntry["profile_template"] = template - if profilesCont.Exists("nodeProfileOverride") { - ptpProfileEntry["override_node_profile"] = profilesCont.S("nodeProfileOverride").Data().(bool) - } - profiles = append(profiles, ptpProfileEntry) - } - d.Set("ptp_profile", profiles) - return nil } @@ -305,10 +201,6 @@ func resourceMSOPtpPolicyCreate(d *schema.ResourceData, m any) error { payload["global"] = globalParams } - if profileEntries, ok := d.GetOk("ptp_profile"); ok { - payload["profiles"] = setPtpProfiles(profileEntries.(*schema.Set)) - } - payloadModel := models.GetPatchPayload("add", "/fabricPolicyTemplate/template/ptpPolicy", payload) templateId := d.Get("template_id").(string) @@ -421,13 +313,6 @@ func resourceMSOPtpPolicyUpdate(d *schema.ResourceData, m any) error { } } - if d.HasChange("ptp_profile") { - err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/profiles", updatePath), setPtpProfiles(d.Get("ptp_profile").(*schema.Set))) - if err != nil { - return err - } - } - err := doPatchRequest(msoClient, fmt.Sprintf("api/v1/templates/%s", templateId), payloadCont) if err != nil { return err diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile.go b/mso/resource_mso_fabric_policies_ptp_policy_profile.go new file mode 100644 index 00000000..076b5193 --- /dev/null +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile.go @@ -0,0 +1,314 @@ +package mso + +import ( + "fmt" + "log" + + "github.com/ciscoecosystem/mso-go-client/client" + "github.com/ciscoecosystem/mso-go-client/container" + "github.com/ciscoecosystem/mso-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" +) + +func resourceMSOPtpPolicyProfile() *schema.Resource { + return &schema.Resource{ + Create: resourceMSOPtpPolicyProfileCreate, + Read: resourceMSOPtpPolicyProfileRead, + Update: resourceMSOPtpPolicyProfileUpdate, + Delete: resourceMSOPtpPolicyProfileDelete, + Importer: &schema.ResourceImporter{ + State: resourceMSOPtpPolicyProfileImport, + }, + + SchemaVersion: 1, + Schema: map[string]*schema.Schema{ + "template_id": { + Type: schema.TypeString, + ForceNew: true, + Required: true, + }, + "name": { + Type: schema.TypeString, + ForceNew: true, + Required: true, + ValidateFunc: validation.StringLenBetween(1, 16), + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "profile_template": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "aes67", "default", "smpte", "telecom", + }, false), + }, + "delay_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-4, 5), + }, + "sync_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-4, 1), + }, + "announce_interval": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(-3, 4), + }, + "announce_timeout": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(2, 10), + }, + "override_node_profile": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + }, + } +} + +func setPtpPolicyProfileData(d *schema.ResourceData, msoClient *client.Client, templateId, policyName string) error { + response, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/templates/%s", templateId)) + if err != nil { + return err + } + + policy, err := GetPolicyByName(response, policyName, "fabricPolicyTemplate", "template", "ptpPolicy", "profiles") + if err != nil { + return err + } + + name := models.StripQuotes(policy.S("name").String()) + d.SetId(fmt.Sprintf("templateId/%s/ptpPolicyProfile/%s", templateId, name)) + d.Set("template_id", templateId) + d.Set("name", name) + d.Set("description", models.StripQuotes(policy.S("description").String())) + d.Set("uuid", models.StripQuotes(policy.S("uuid").String())) + d.Set("delay_interval", policy.S("delayIntvl").Data().(float64)) + d.Set("sync_interval", policy.S("syncIntvl").Data().(float64)) + d.Set("announce_interval", policy.S("announceIntvl").Data().(float64)) + d.Set("announce_timeout", policy.S("announceTimeout").Data().(float64)) + template := models.StripQuotes(policy.S("profileTemplate").String()) + if template == "telecomFullPath" { + template = "telecom" + } + d.Set("profile_template", template) + if policy.Exists("nodeProfileOverride") { + d.Set("override_node_profile", policy.S("nodeProfileOverride").Data().(bool)) + } + + return nil +} + +func resourceMSOPtpPolicyProfileImport(d *schema.ResourceData, m any) ([]*schema.ResourceData, error) { + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Beginning Import: %v", d.Id()) + msoClient := m.(*client.Client) + + templateId, err := GetTemplateIdFromResourceId(d.Id()) + if err != nil { + return nil, err + } + + policyName, err := GetPolicyNameFromResourceId(d.Id(), "ptpPolicyProfile") + if err != nil { + return nil, err + } + + setPtpPolicyProfileData(d, msoClient, templateId, policyName) + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Import Complete: %v", d.Id()) + return []*schema.ResourceData{d}, nil +} + +func resourceMSOPtpPolicyProfileCreate(d *schema.ResourceData, m any) error { + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Beginning Create: %v", d.Id()) + msoClient := m.(*client.Client) + + payload := map[string]any{} + + payload["name"] = d.Get("name").(string) + + if description, ok := d.GetOk("description"); ok { + payload["description"] = description.(string) + } + + if profile_template, ok := d.GetOk("profile_template"); ok { + if profile_template == "telecom" { + profile_template = "telecomFullPath" + } + payload["profileTemplate"] = profile_template.(string) + } + + if announce_interval, ok := d.GetOk("announce_interval"); ok { + payload["announceIntvl"] = announce_interval.(int) + } + + if sync_interval, ok := d.GetOk("sync_interval"); ok { + payload["syncIntvl"] = sync_interval.(int) + } + + if delay_interval, ok := d.GetOk("delay_interval"); ok { + payload["delayIntvl"] = delay_interval.(int) + } + + if announce_timeout, ok := d.GetOk("announce_timeout"); ok { + payload["announceTimeout"] = announce_timeout.(int) + } + + if override_node_profile, ok := d.GetOk("override_node_profile"); ok { + if override_node_profile.(bool) { + payload["announceIntvl"] = override_node_profile.(bool) + } + } + + payloadModel := models.GetPatchPayload("add", "/fabricPolicyTemplate/template/ptpPolicy/profiles/-", payload) + templateId := d.Get("template_id").(string) + + _, err := msoClient.PatchbyID(fmt.Sprintf("api/v1/templates/%s", templateId), payloadModel) + if err != nil { + return err + } + + d.SetId(fmt.Sprintf("templateId/%s/ptpPolicyProfile/%s", templateId, d.Get("name").(string))) + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Create Complete: %v", d.Id()) + return resourceMSOPtpPolicyProfileRead(d, m) +} + +func resourceMSOPtpPolicyProfileRead(d *schema.ResourceData, m any) error { + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Beginning Read: %v", d.Id()) + msoClient := m.(*client.Client) + + templateId := d.Get("template_id").(string) + policyName := d.Get("name").(string) + + setPtpPolicyProfileData(d, msoClient, templateId, policyName) + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Read Complete : %v", d.Id()) + return nil +} + +func resourceMSOPtpPolicyProfileUpdate(d *schema.ResourceData, m any) error { + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Beginning Update: %v", d.Id()) + msoClient := m.(*client.Client) + templateId := d.Get("template_id").(string) + + templateCont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/templates/%s", templateId)) + if err != nil { + return err + } + + policyIndex, err := GetPolicyIndexByKeyAndValue(templateCont, "uuid", d.Get("uuid").(string), "fabricPolicyTemplate", "template", "ptpPolicy", "profiles") + if err != nil { + return err + } + + updatePath := fmt.Sprintf("/fabricPolicyTemplate/template/ptpPolicy/profiles/%d", policyIndex) + + payloadCont := container.New() + payloadCont.Array() + if d.HasChange("name") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/name", updatePath), d.Get("name").(string)) + if err != nil { + return err + } + } + + if d.HasChange("description") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/description", updatePath), d.Get("description").(string)) + if err != nil { + return err + } + } + + if d.HasChange("profile_template") { + profile_template := d.Get("profile_template").(string) + if (profile_template == "telecom") { + profile_template = "telecomFullPath" + } + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/profileTemplate", updatePath), profile_template) + if err != nil { + return err + } + } + + if d.HasChange("announce_interval") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/announceIntvl", updatePath), d.Get("announce_interval").(int)) + if err != nil { + return err + } + } + + if d.HasChange("sync_interval") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/syncIntvl", updatePath), d.Get("sync_interval").(int)) + if err != nil { + return err + } + } + + if d.HasChange("delay_interval") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/delayIntvl", updatePath), d.Get("delay_interval").(int)) + if err != nil { + return err + } + } + + if d.HasChange("announce_timeout") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/announceTimeout", updatePath), d.Get("announce_timeout").(int)) + if err != nil { + return err + } + } + + if d.HasChange("override_node_profile") { + override := d.Get("override_node_profile").(bool) + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/nodeProfileOverride", updatePath), override) + if err != nil { + return err + } + } + + err = doPatchRequest(msoClient, fmt.Sprintf("api/v1/templates/%s", templateId), payloadCont) + if err != nil { + return err + } + + d.SetId(fmt.Sprintf("templateId/%s/ptpPolicyProfile/%s", templateId, d.Get("name").(string))) + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Update Complete: %v", d.Id()) + return resourceMSOPtpPolicyProfileRead(d, m) +} + +func resourceMSOPtpPolicyProfileDelete(d *schema.ResourceData, m any) error { + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Beginning Delete: %v", d.Id()) + msoClient := m.(*client.Client) + + templateCont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/templates/%s", d.Get("template_id").(string))) + if err != nil { + return err + } + + policyIndex, err := GetPolicyIndexByKeyAndValue(templateCont, "uuid", d.Get("uuid").(string), "fabricPolicyTemplate", "template", "ptpPolicy", "profiles") + if err != nil { + return err + } + + payloadModel := models.GetRemovePatchPayload(fmt.Sprintf("/fabricPolicyTemplate/template/ptpPolicy/profiles/%d", policyIndex)) + + _, err = msoClient.PatchbyID(fmt.Sprintf("api/v1/templates/%s", d.Get("template_id").(string)), payloadModel) + if err != nil { + return err + } + + d.SetId("") + log.Printf("[DEBUG] MSO PTP Policy Profile Resource - Delete Complete: %v", d.Id()) + return nil +} diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go new file mode 100644 index 00000000..02e97b66 --- /dev/null +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go @@ -0,0 +1,128 @@ +package mso + +import ( + "fmt" + "testing" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccMSOPtpPolicyProfileResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + PreConfig: func() { fmt.Println("Test: Create PTP Policy Profile") }, + Config: testAccMSOPtpPolicyProfileConfigCreate(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "description", "Terraform test PTP Policy Profile"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "aes67"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_timeout", "3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "override_node_profile", "false"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "uuid"), + ), + }, + { + PreConfig: func() { fmt.Println("Test: Update PTP Policy Profile") }, + Config: testAccMSOPtpPolicyProfileConfigUpdate(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "description", "Terraform test PTP Policy Profile updated"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "smpte"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_interval", "-3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_timeout", "10"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "override_node_profile", "true"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "uuid"), + ), + }, + { + PreConfig: func() { fmt.Println("Test: Create second PTP Policy Profile") }, + Config: testAccMSOPtpPolicyProfileConfigCreate2(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "name", "tf_ptp_profile_2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "description", "Terraform test PTP Policy Profile 2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "profile_template", "telecom"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "delay_interval", "-4"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "sync_interval", "-4"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "announce_interval", "-3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "announce_timeout", "3"), + resource.TestCheckNoResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "override_node_profile"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "uuid"), + ), + }, + { + PreConfig: func() { fmt.Println("Test: Import PTP Policy Profile") }, + ResourceName: "mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", + ImportState: true, + ImportStateVerify: true, + }, + }, + CheckDestroy: testCheckResourceDestroyPolicyWithPathAttributesAndArguments("mso_fabric_policies_ptp_policy_profile", "fabricPolicyTemplate", "template", "ptpPolicy", "profiles"), + }) +} + +func testAccMSOPtpPolicyProfileConfigCreate() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { + template_id = mso_template.template_fabric_policy.id + name = "tf_ptp_profile" + description = "Terraform test PTP Policy Profile" + profile_template = "aes67" + delay_interval = -2 + sync_interval = -3 + announce_timeout = 3 + announce_interval = 1 + override_node_profile = false + + # Explicit dependency on PTP Policy + depends_on = [ + mso_fabric_policies_ptp_policy.ptp_policy + ] + }`, testAccMSOPtpPolicyConfigCreate()) +} + +func testAccMSOPtpPolicyProfileConfigUpdate() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { + template_id = mso_template.template_fabric_policy.id + name = "tf_ptp_profile" + description = "Terraform test PTP Policy Profile updated" + profile_template = "smpte" + delay_interval = -2 + sync_interval = -2 + announce_timeout = 10 + announce_interval = -3 + override_node_profile = true + + # Explicit dependency on PTP Policy + depends_on = [ + mso_fabric_policies_ptp_policy.ptp_policy + ] + }`, testAccMSOPtpPolicyConfigCreate()) +} + +func testAccMSOPtpPolicyProfileConfigCreate2() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile_2" { + template_id = mso_template.template_fabric_policy.id + name = "tf_ptp_profile_2" + description = "Terraform test PTP Policy Profile 2" + profile_template = "telecom" + announce_interval = -3 + delay_interval = -4 + sync_interval = -4 + announce_timeout = 3 + + # Explicit dependency on PTP Policy + depends_on = [ + mso_fabric_policies_ptp_policy.ptp_policy + ] + }`, testAccMSOPtpPolicyProfileConfigUpdate()) +} + diff --git a/mso/resource_mso_fabric_policies_ptp_policy_test.go b/mso/resource_mso_fabric_policies_ptp_policy_test.go index c8625725..bb9cfec7 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_test.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_test.go @@ -26,18 +26,7 @@ func TestAccMSOPtpPolicyResource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile.#", "1"), - customTestCheckResourceTypeSetAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile", - map[string]string{ - "name" : "profile1", - "delay_interval" : "-2", - "profile_template" : "aes67", - "sync_interval" : "-3", - "announce_timeout" : "3", - "announce_interval" : "1", - "override_node_profile" : "false", - }, - ), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy.ptp_policy", "uuid"), ), }, { @@ -55,46 +44,7 @@ func TestAccMSOPtpPolicyResource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile.#", "2"), - customTestCheckResourceTypeSetAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile", - map[string]string{ - "name" : "profile1", - "delay_interval" : "-2", - "profile_template" : "aes67", - "sync_interval" : "-3", - "announce_timeout" : "3", - "announce_interval" : "1", - "override_node_profile" : "false", - }, - ), - customTestCheckResourceTypeSetAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile", - map[string]string{ - "name" : "profile2", - "delay_interval" : "-2", - "profile_template" : "aes67", - "sync_interval" : "-3", - "announce_timeout" : "3", - "announce_interval" : "1", - "override_node_profile" : "false", - }, - ), - ), - }, - { - PreConfig: func() { fmt.Println("Test: Update PTP Policy remove one profile") }, - Config: testAccMSOPtpPolicyConfigUpdateRemoveProfile(), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy disabled"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "disabled"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "default"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority1", "255"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority2", "254"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_domain", "100"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_interval", "1"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy.ptp_policy", "uuid"), ), }, { @@ -112,7 +62,7 @@ func TestAccMSOPtpPolicyResource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-4"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "-2"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "10"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "ptp_profile.#", "0"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy.ptp_policy", "uuid"), ), }, { @@ -122,7 +72,7 @@ func TestAccMSOPtpPolicyResource(t *testing.T) { ImportStateVerify: true, }, }, - CheckDestroy: testCheckResourceDestroyPolicyWithPathAttributesAndArguments("mso_fabric_policies_ptp_policy", "fabricPolicyTemplate", "template", "ptpProfile"), + CheckDestroy: testCheckResourceDestroyPolicyWithPathAttributesAndArguments("mso_fabric_policies_ptp_policy", "fabricPolicyTemplate", "template", "ptpPolicy"), }) } @@ -141,15 +91,6 @@ func testAccMSOPtpPolicyConfigCreate() string { fabric_sync_interval = -1 fabric_delay_interval = 1 fabric_announce_timeout = 3 - ptp_profile { - name = "profile1" - profile_template = "aes67" - delay_interval = -2 - sync_interval = -3 - announce_timeout = 3 - announce_interval = 1 - override_node_profile = false - } }`, testAccMSOTemplateResourceFabricPolicyConfig()) } @@ -168,49 +109,6 @@ func testAccMSOPtpPolicyConfigUpdateDisable() string { fabric_sync_interval = -1 fabric_delay_interval = 1 fabric_announce_timeout = 3 - ptp_profile { - name = "profile1" - profile_template = "aes67" - delay_interval = -2 - sync_interval = -3 - announce_timeout = 3 - announce_interval = 1 - override_node_profile = false - } - ptp_profile { - name = "profile2" - profile_template = "telecom" - announce_interval = -3 - delay_interval = -4 - sync_interval = -4 - announce_timeout = 3 - } - }`, testAccMSOTemplateResourceFabricPolicyConfig()) -} - -func testAccMSOPtpPolicyConfigUpdateRemoveProfile() string { - return fmt.Sprintf(`%s - resource "mso_fabric_policies_ptp_policy" "ptp_policy" { - template_id = mso_template.template_fabric_policy.id - name = "tf_test_ptp_policy" - description = "Terraform test PTP Policy disabled" - admin_state = "disabled" - fabric_profile_template = "default" - global_priority1 = 255 - global_priority2 = 254 - global_domain = 100 - fabric_announce_interval = 1 - fabric_sync_interval = -1 - fabric_delay_interval = 1 - fabric_announce_timeout = 3 - ptp_profile { - name = "profile2" - profile_template = "telecom" - announce_interval = -3 - delay_interval = -4 - sync_interval = -4 - announce_timeout = 3 - } }`, testAccMSOTemplateResourceFabricPolicyConfig()) } diff --git a/website/docs/d/fabric_policies_ptp_policy.html.markdown b/website/docs/d/fabric_policies_ptp_policy.html.markdown index 512ee7d6..ca03f1f2 100644 --- a/website/docs/d/fabric_policies_ptp_policy.html.markdown +++ b/website/docs/d/fabric_policies_ptp_policy.html.markdown @@ -42,13 +42,3 @@ data "mso_fabric_policies_ptp_policy" "ptp_policy" { * `fabric_sync_interval` - (Read-Only) The fabric sync interval of the PTP Policy. * `fabric_delay_interval` - (Read-Only) The fabric delay interval of the PTP Policy. * `fabric_announce_timeout` - (Read-Only) The fabric announce timeout of the PTP Policy. -* `ptp_profiles` - (Read-Only) The list of PTP Profiles. - * `name` - (Read-Only) The name of the PTP Profile. - * `uuid` - (Read-Only) The NDO UUID of the PTP Profile. - * `description` - (Read-Only) The description of the PTP Profile. - * `delay_interval` - (Read-Only) The delay interval of the PTP Profile. - * `profile_template` - (Read-Only) The profile template of the PTP Profile. - * `sync_interval` - (Read-Only) The sync interval of the PTP Profile. - * `override_node_profile` - (Read-Only) The node profile override of the PTP Profile. - * `announce_timeout` - (Read-Only) The announce timeout of the PTP Profile. - * `announce_interval` - (Read-Only) The announce interval of the PTP Profile. diff --git a/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown b/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown new file mode 100644 index 00000000..c32df637 --- /dev/null +++ b/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown @@ -0,0 +1,41 @@ +--- +layout: "mso" +page_title: "MSO: mso_fabric_policies_ptp_policy_profile" +sidebar_current: "docs-mso-data-source-fabric_policies_ptp_policy" +description: |- + Data source for PTP Profiles on Cisco Nexus Dashboard Orchestrator (NDO) +--- + +# mso_fabric_policies_ptp_policy_profile # + +Data source for (Precision Time Protocol) PTP Policy Profiles on Cisco Nexus Dashboard Orchestrator (NDO). This data source is supported in NDO v4.3(1) or higher. + +## GUI Information ## + +* `Location` - Manage -> Fabric Template -> Fabric Policies -> PTP Policy -> Profiles + +## Example Usage ## + +```hcl +data "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { + template_id = mso_template.fabric_policy_template.id + name = "ptp_profile" +} +``` + +## Argument Reference ## + +* `template_id` - (Required) The unique ID of the Fabric Policy template. +* `name` - (Required) The name of the PTP Profile. + +## Attribute Reference ## + +* `uuid` - (Read-Only) The NDO UUID of the PTP Profile. +* `id` - (Read-Only) The unique Terraform identifier of the PTP Profile. +* `description` - (Read-Only) The description of the PTP Profile. +* `delay_interval` - (Read-Only) The delay interval of the PTP Profile. +* `profile_template` - (Read-Only) The profile template of the PTP Profile. +* `sync_interval` - (Read-Only) The sync interval of the PTP Profile. +* `override_node_profile` - (Read-Only) The node profile override of the PTP Profile. +* `announce_timeout` - (Read-Only) The announce timeout of the PTP Profile. +* `announce_interval` - (Read-Only) The announce interval of the PTP Profile. diff --git a/website/docs/r/fabric_policies_ptp_policy.html.markdown b/website/docs/r/fabric_policies_ptp_policy.html.markdown index 57011770..ca0d17fc 100644 --- a/website/docs/r/fabric_policies_ptp_policy.html.markdown +++ b/website/docs/r/fabric_policies_ptp_policy.html.markdown @@ -18,11 +18,18 @@ Manages PTP Policies on Cisco Nexus Dashboard Orchestrator (NDO). This resource ```hcl resource "mso_fabric_policies_ptp_policy" "ptp_policy" { - template_id = mso_template.fabric_policy_template.id - name = "ptp_policy" - description = "Example description" - admin_state = "enabled" - TODO + template_id = mso_template.fabric_policy_template.id + name = "ptp_policy" + description = "Example description" + admin_state = "enabled" + global_priority1 = 250 + global_priority2 = 100 + global_domain = 99 + fabric_profile_template = "aes67" + fabric_announce_interval = 1 + fabric_sync_interval = -3 + fabric_delay_interval = -2 + fabric_announce_timeout = 3 } ``` @@ -40,15 +47,6 @@ resource "mso_fabric_policies_ptp_policy" "ptp_policy" { * `fabric_sync_interval` - (Required) The fabric sync interval in log base 2 seconds of the PTP Policy. Valid range: -4 to 1. * `fabric_delay_interval` - (Required) The fabric delay interval in log base 2 seconds of the PTP Policy. Valid range: -4 to 5. * `fabric_announce_timeout` - (Required) The fabric announce interval timeout count of the PTP Policy. Valid range: 2 to 10. -* `ptp_profiles` - (Optional) The list of PTP Profiles. - * `name` - (Required) The name of the PTP Profile. - * `description` - (Optional) The description of the PTP Profile. - * `delay_interval` - (Required) The minimum delay request interval in log base 2 seconds of the PTP Profile. Valid range: -4 to 5. - * `profile_template` - (Required) The profile template of the PTP Profile. Allowed values are `default`, `aes67`, `smpte` or `telecom`. - * `sync_interval` - (Required) The sync interval in log base 2 seconds of the PTP Profile.Valid range: -4 to 1. - * `override_node_profile` - (Optional) The node profile override of the PTP Profile. Allowed Values: `true` or `false`. - * `announce_timeout` - (Required) The announce interval timeout count of the PTP Profile. Valid range: 2 to 10. - * `announce_interval` - (Required) The announce interval in log base 2 seconds of the PTP Profile. Valid range: -3 to 4. ## Attribute Reference ## diff --git a/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown b/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown new file mode 100644 index 00000000..037e153c --- /dev/null +++ b/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown @@ -0,0 +1,56 @@ +--- +layout: "mso" +page_title: "MSO: mso_fabric_policies_ptp_policy_profile" +sidebar_current: "docs-mso-resource-fabric_policies_ptp_policy_profile" +description: |- + Manages PTP Policy Profiles on Cisco Nexus Dashboard Orchestrator (NDO) +--- + +# mso_fabric_policies_ptp_policy_profile # + +Manages (Precision Time Protocol) PTP Policy Profiles on Cisco Nexus Dashboard Orchestrator (NDO). This resource is supported in NDO v4.3(1) or higher. + +## GUI Information ## + +* `Location` - Manage -> Fabric Template -> Fabric Policies -> PTP Policy -> Profiles + +## Example Usage ## + +```hcl +resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { + template_id = mso_template.fabric_policy_template.id + name = "ptp_policy_profile" + description = "Example description" + delay_interval = -2 + sync_interval = -3 + announce_timeout = 3 + announce_interval = 1 + profile_template = "aes67" + override_node_profile = false +} +``` + +## Argument Reference ## + +* `template_id` - (Required) The unique ID of the Fabric Policy template. +* `name` - (Required) The name of the PTP Profile. +* `description` - (Optional) The description of the PTP Profile. +* `profile_template` - (Required) The profile template of the PTP Profile. Allowed values are `default`, `aes67`, `smpte` or `telecom`. +* `delay_interval` - (Required) The minimum delay request interval in log base 2 seconds of the PTP Profile. Valid range: -4 to 5. +* `announce_timeout` - (Required) The announce interval timeout count of the PTP Profile. Valid range: 2 to 10. +* `announce_interval` - (Required) The announce interval in log base 2 seconds of the PTP Profile. Valid range: -3 to 4. +* `sync_interval` - (Required) The sync interval in log base 2 seconds of the PTP Profile.Valid range: -4 to 1. +* `override_node_profile` - (Optional) The node profile override of the PTP Profile. Allowed Values: `true` or `false`. + +## Attribute Reference ## + +* `uuid` - (Read-Only) The NDO UUID of the PTP Profile. +* `id` - (Read-Only) The unique Terraform identifier of the PTP Profile. + +## Importing ## + +An existing MSO PTP Policy can be [imported][docs-import] into this resource via its ID/path, via the following command: [docs-import]: + +```bash +terraform import mso_fabric_policies_ptp_policy_profile.ptp_policy templateId/{template_id}/ptpPolicyProfile/{name} +``` From b6ad1fc81b21a66480161495d932f38ca936f9d3 Mon Sep 17 00:00:00 2001 From: samitab Date: Wed, 18 Feb 2026 14:50:41 +1000 Subject: [PATCH 3/8] [ignore] go format --- ..._mso_fabric_policies_ptp_policy_profile.go | 8 ++--- ...resource_mso_fabric_policies_ptp_policy.go | 30 +++++++++---------- ..._mso_fabric_policies_ptp_policy_profile.go | 8 ++--- ...fabric_policies_ptp_policy_profile_test.go | 3 +- ...rce_mso_fabric_policies_ptp_policy_test.go | 2 +- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go index 8e2c66fb..33cbf7a0 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go @@ -33,19 +33,19 @@ func datasourceMSOPtpPolicyProfile() *schema.Resource { Computed: true, }, "delay_interval": { - Type: schema.TypeInt, + Type: schema.TypeInt, Computed: true, }, "sync_interval": { - Type: schema.TypeInt, + Type: schema.TypeInt, Computed: true, }, "announce_interval": { - Type: schema.TypeInt, + Type: schema.TypeInt, Computed: true, }, "announce_timeout": { - Type: schema.TypeInt, + Type: schema.TypeInt, Computed: true, }, "override_node_profile": { diff --git a/mso/resource_mso_fabric_policies_ptp_policy.go b/mso/resource_mso_fabric_policies_ptp_policy.go index 2caee096..6ac847bc 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy.go +++ b/mso/resource_mso_fabric_policies_ptp_policy.go @@ -58,38 +58,38 @@ func resourceMSOPtpPolicy() *schema.Resource { }, false), }, "global_priority1": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validation.IntBetween(0, 255), }, "global_priority2": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validation.IntBetween(0, 255), }, "global_domain": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validation.IntBetween(0, 128), }, "fabric_sync_interval": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validation.IntBetween(-4, 1), }, "fabric_delay_interval": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validation.IntBetween(-4, 5), }, "fabric_announce_interval": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validation.IntBetween(-3, 4), }, "fabric_announce_timeout": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validation.IntBetween(2, 10), }, }, @@ -235,7 +235,7 @@ func resourceMSOPtpPolicyUpdate(d *schema.ResourceData, m any) error { payloadCont := container.New() payloadCont.Array() - + if d.HasChange("name") { err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/name", updatePath), d.Get("name").(string)) if err != nil { diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile.go b/mso/resource_mso_fabric_policies_ptp_policy_profile.go index 076b5193..36a334fe 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile.go @@ -29,9 +29,9 @@ func resourceMSOPtpPolicyProfile() *schema.Resource { Required: true, }, "name": { - Type: schema.TypeString, - ForceNew: true, - Required: true, + Type: schema.TypeString, + ForceNew: true, + Required: true, ValidateFunc: validation.StringLenBetween(1, 16), }, "description": { @@ -232,7 +232,7 @@ func resourceMSOPtpPolicyProfileUpdate(d *schema.ResourceData, m any) error { if d.HasChange("profile_template") { profile_template := d.Get("profile_template").(string) - if (profile_template == "telecom") { + if profile_template == "telecom" { profile_template = "telecomFullPath" } err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/profileTemplate", updatePath), profile_template) diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go index 02e97b66..0c987f54 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go @@ -2,8 +2,8 @@ package mso import ( "fmt" - "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "testing" ) func TestAccMSOPtpPolicyProfileResource(t *testing.T) { @@ -125,4 +125,3 @@ func testAccMSOPtpPolicyProfileConfigCreate2() string { ] }`, testAccMSOPtpPolicyProfileConfigUpdate()) } - diff --git a/mso/resource_mso_fabric_policies_ptp_policy_test.go b/mso/resource_mso_fabric_policies_ptp_policy_test.go index bb9cfec7..427baa76 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_test.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_test.go @@ -2,8 +2,8 @@ package mso import ( "fmt" - "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "testing" ) func TestAccMSOPtpPolicyResource(t *testing.T) { From 8f2b91b8aece567a7f3516f3aeec9f81dd4499f7 Mon Sep 17 00:00:00 2001 From: samitab Date: Wed, 18 Feb 2026 17:07:32 +1000 Subject: [PATCH 4/8] [ignore] Add telecom only attributes to PTP resources. --- mso/constants.go | 22 +++++ ..._mso_fabric_policies_ptp_policy_profile.go | 12 +++ ...fabric_policies_ptp_policy_profile_test.go | 36 +++++++-- ..._mso_fabric_policies_ptp_policy_profile.go | 80 +++++++++++++++---- ...fabric_policies_ptp_policy_profile_test.go | 68 +++++++++++++--- ..._policies_ptp_policy_profile.html.markdown | 3 + ..._policies_ptp_policy_profile.html.markdown | 5 +- 7 files changed, 195 insertions(+), 31 deletions(-) diff --git a/mso/constants.go b/mso/constants.go index a2b6eb46..b2305458 100644 --- a/mso/constants.go +++ b/mso/constants.go @@ -95,3 +95,25 @@ var loadBalanceHashingMap = map[string]string{ "layer_4_source_ip": "l4-src-port", "source_ip": "src-ip", } + +var ptpProfileTemplateMap = map[string]string{ + "aes67": "aes67", + "default": "default", + "smpte": "smpte", + "telecom": "telecomFullPath", + "telecomFullPath": "telecom", +} + +var ptpDestinationMacMap = map[string]string{ + "forwardable": "forwardable", + "non_forwardable": "nonForwardable", + "nonForwardable": "non_forwardable", +} + +var ptpMismatchedMacHandlingMap = map[string]string{ + "drop": "drop", + "reply_with_config_mac": "replyWithCfgMac", + "replyWithCfgMac": "reply_with_config_mac", + "reply_with_received_mac": "replyWithRxMac", + "replyWithRxMac": "reply_with_received_mac", +} diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go index 33cbf7a0..10e728de 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go @@ -52,6 +52,18 @@ func datasourceMSOPtpPolicyProfile() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + "local_priority": { + Type: schema.TypeInt, + Computed: true, + }, + "destination_mac_type": { + Type: schema.TypeString, + Computed: true, + }, + "mismatched_mac_handling": { + Type: schema.TypeString, + Computed: true, + }, }, } } diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go index 315dfa79..9c88422d 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go @@ -18,11 +18,14 @@ func TestAccMSOPtpPolicyProfileDataSource(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "description", "Terraform test PTP Policy Profile"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "aes67"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-2"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-3"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_interval", "1"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "telecom"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-4"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-4"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_interval", "-3"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_timeout", "3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "local_priority", "120"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "destination_mac_type", "forwardable"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "mismatched_mac_handling", "reply_with_config_mac"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "override_node_profile", "false"), resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "uuid"), ), @@ -31,10 +34,33 @@ func TestAccMSOPtpPolicyProfileDataSource(t *testing.T) { }) } +func testAccMSOPtpPolicyProfileConfig() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { + template_id = mso_template.template_fabric_policy.id + name = "tf_ptp_profile" + description = "Terraform test PTP Policy Profile" + profile_template = "telecom" + announce_interval = -3 + delay_interval = -4 + sync_interval = -4 + announce_timeout = 3 + local_priority = 120 + destination_mac_type = "forwardable" + mismatched_mac_handling = "reply_with_config_mac" + override_node_profile = "false" + + # Explicit dependency on PTP Policy + depends_on = [ + mso_fabric_policies_ptp_policy.ptp_policy + ] + }`, testAccMSOPtpPolicyConfigCreate()) +} + func testAccMSOPtpPolicyProfileDataSource() string { return fmt.Sprintf(`%s data "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { template_id = mso_fabric_policies_ptp_policy_profile.ptp_policy_profile.template_id name = "tf_ptp_profile" - }`, testAccMSOPtpPolicyProfileConfigCreate()) + }`, testAccMSOPtpPolicyProfileConfig()) } diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile.go b/mso/resource_mso_fabric_policies_ptp_policy_profile.go index 36a334fe..46088619 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile.go @@ -75,6 +75,27 @@ func resourceMSOPtpPolicyProfile() *schema.Resource { Optional: true, Computed: true, }, + "local_priority": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "destination_mac_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "forwardable", "non_forwardable", + }, false), + }, + "mismatched_mac_handling": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "drop", "reply_with_config_mac", "reply_with_received_mac", + }, false), + }, }, } } @@ -100,14 +121,19 @@ func setPtpPolicyProfileData(d *schema.ResourceData, msoClient *client.Client, t d.Set("sync_interval", policy.S("syncIntvl").Data().(float64)) d.Set("announce_interval", policy.S("announceIntvl").Data().(float64)) d.Set("announce_timeout", policy.S("announceTimeout").Data().(float64)) - template := models.StripQuotes(policy.S("profileTemplate").String()) - if template == "telecomFullPath" { - template = "telecom" - } - d.Set("profile_template", template) + d.Set("profile_template", convertValueWithMap(models.StripQuotes(policy.S("profileTemplate").String()), ptpProfileTemplateMap)) if policy.Exists("nodeProfileOverride") { d.Set("override_node_profile", policy.S("nodeProfileOverride").Data().(bool)) } + if policy.Exists("localPriority") { + d.Set("local_priority", policy.S("localPriority").Data().(float64)) + } + if policy.Exists("dstMacType") { + d.Set("destination_mac_type", convertValueWithMap(models.StripQuotes(policy.S("dstMacType").String()), ptpDestinationMacMap)) + } + if policy.Exists("dstMacRxNoMatch") { + d.Set("mismatched_mac_handling", convertValueWithMap(models.StripQuotes(policy.S("dstMacRxNoMatch").String()), ptpMismatchedMacHandlingMap)) + } return nil } @@ -144,10 +170,7 @@ func resourceMSOPtpPolicyProfileCreate(d *schema.ResourceData, m any) error { } if profile_template, ok := d.GetOk("profile_template"); ok { - if profile_template == "telecom" { - profile_template = "telecomFullPath" - } - payload["profileTemplate"] = profile_template.(string) + payload["profileTemplate"] = convertValueWithMap(profile_template.(string), ptpProfileTemplateMap) } if announce_interval, ok := d.GetOk("announce_interval"); ok { @@ -172,6 +195,18 @@ func resourceMSOPtpPolicyProfileCreate(d *schema.ResourceData, m any) error { } } + if local_priority, ok := d.GetOk("local_priority"); ok { + payload["localPriority"] = local_priority.(int) + } + + if destination_mac_type, ok := d.GetOk("destination_mac_type"); ok { + payload["dstMacType"] = convertValueWithMap(destination_mac_type.(string), ptpDestinationMacMap) + } + + if mismatched_mac_handling, ok := d.GetOk("mismatched_mac_handling"); ok { + payload["dstMacRxNoMatch"] = convertValueWithMap(mismatched_mac_handling.(string), ptpMismatchedMacHandlingMap) + } + payloadModel := models.GetPatchPayload("add", "/fabricPolicyTemplate/template/ptpPolicy/profiles/-", payload) templateId := d.Get("template_id").(string) @@ -231,11 +266,7 @@ func resourceMSOPtpPolicyProfileUpdate(d *schema.ResourceData, m any) error { } if d.HasChange("profile_template") { - profile_template := d.Get("profile_template").(string) - if profile_template == "telecom" { - profile_template = "telecomFullPath" - } - err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/profileTemplate", updatePath), profile_template) + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/profileTemplate", updatePath), convertValueWithMap(d.Get("profile_template").(string), ptpProfileTemplateMap)) if err != nil { return err } @@ -277,6 +308,27 @@ func resourceMSOPtpPolicyProfileUpdate(d *schema.ResourceData, m any) error { } } + if d.HasChange("local_priority") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/localPriority", updatePath), d.Get("local_priority").(int)) + if err != nil { + return err + } + } + + if d.HasChange("destination_mac_type") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/dstMacType", updatePath), convertValueWithMap(d.Get("destination_mac_type").(string), ptpDestinationMacMap)) + if err != nil { + return err + } + } + + if d.HasChange("mismatched_mac_handling") { + err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/dstMacRxNoMatch", updatePath), convertValueWithMap(d.Get("mismatched_mac_handling").(string), ptpMismatchedMacHandlingMap)) + if err != nil { + return err + } + } + err = doPatchRequest(msoClient, fmt.Sprintf("api/v1/templates/%s", templateId), payloadCont) if err != nil { return err diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go index 0c987f54..5fc1ebbb 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go @@ -42,8 +42,8 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { ), }, { - PreConfig: func() { fmt.Println("Test: Create second PTP Policy Profile") }, - Config: testAccMSOPtpPolicyProfileConfigCreate2(), + PreConfig: func() { fmt.Println("Test: Create Telecom PTP Policy Profile") }, + Config: testAccMSOPtpPolicyProfileConfigCreateTelecom(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "name", "tf_ptp_profile_2"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "description", "Terraform test PTP Policy Profile 2"), @@ -52,6 +52,27 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "sync_interval", "-4"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "announce_interval", "-3"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "announce_timeout", "3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "local_priority", "120"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "destination_mac_type", "forwardable"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "mismatched_mac_handling", "reply_with_config_mac"), + resource.TestCheckNoResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "override_node_profile"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "uuid"), + ), + }, + { + PreConfig: func() { fmt.Println("Test: Update Telecom PTP Policy Profile") }, + Config: testAccMSOPtpPolicyProfileConfigUpdateTelecom(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "name", "tf_ptp_profile_2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "description", "Terraform test PTP Policy Profile 2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "profile_template", "telecom"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "delay_interval", "-4"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "sync_interval", "-4"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "announce_interval", "-3"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "announce_timeout", "2"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "local_priority", "99"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "destination_mac_type", "non_forwardable"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "mismatched_mac_handling", "reply_with_received_mac"), resource.TestCheckNoResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "override_node_profile"), resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "uuid"), ), @@ -107,17 +128,42 @@ func testAccMSOPtpPolicyProfileConfigUpdate() string { }`, testAccMSOPtpPolicyConfigCreate()) } -func testAccMSOPtpPolicyProfileConfigCreate2() string { +func testAccMSOPtpPolicyProfileConfigCreateTelecom() string { return fmt.Sprintf(`%s resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile_2" { - template_id = mso_template.template_fabric_policy.id - name = "tf_ptp_profile_2" - description = "Terraform test PTP Policy Profile 2" - profile_template = "telecom" - announce_interval = -3 - delay_interval = -4 - sync_interval = -4 - announce_timeout = 3 + template_id = mso_template.template_fabric_policy.id + name = "tf_ptp_profile_2" + description = "Terraform test PTP Policy Profile 2" + profile_template = "telecom" + announce_interval = -3 + delay_interval = -4 + sync_interval = -4 + announce_timeout = 3 + local_priority = 120 + destination_mac_type = "forwardable" + mismatched_mac_handling = "reply_with_config_mac" + + # Explicit dependency on PTP Policy + depends_on = [ + mso_fabric_policies_ptp_policy.ptp_policy + ] + }`, testAccMSOPtpPolicyProfileConfigUpdate()) +} + +func testAccMSOPtpPolicyProfileConfigUpdateTelecom() string { + return fmt.Sprintf(`%s + resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile_2" { + template_id = mso_template.template_fabric_policy.id + name = "tf_ptp_profile_2" + description = "Terraform test PTP Policy Profile 2" + profile_template = "telecom" + announce_interval = -3 + delay_interval = -4 + sync_interval = -4 + announce_timeout = 2 + local_priority = 99 + destination_mac_type = "non_forwardable" + mismatched_mac_handling = "reply_with_received_mac" # Explicit dependency on PTP Policy depends_on = [ diff --git a/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown b/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown index c32df637..31f7b139 100644 --- a/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown +++ b/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown @@ -39,3 +39,6 @@ data "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { * `override_node_profile` - (Read-Only) The node profile override of the PTP Profile. * `announce_timeout` - (Read-Only) The announce timeout of the PTP Profile. * `announce_interval` - (Read-Only) The announce interval of the PTP Profile. +* `local_priority` - (Read-Only) The local priority of the PTP Profile. +* `destination_mac_type` - (Read-Only) The destination MAC for PTP messages of the PTP Profile. +* `mismatched_mac_handling` - (Read-Only) The mismatched destination MAC handling of the PTP Profile. diff --git a/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown b/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown index 037e153c..0a5b45a7 100644 --- a/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown +++ b/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown @@ -40,7 +40,10 @@ resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { * `announce_timeout` - (Required) The announce interval timeout count of the PTP Profile. Valid range: 2 to 10. * `announce_interval` - (Required) The announce interval in log base 2 seconds of the PTP Profile. Valid range: -3 to 4. * `sync_interval` - (Required) The sync interval in log base 2 seconds of the PTP Profile.Valid range: -4 to 1. -* `override_node_profile` - (Optional) The node profile override of the PTP Profile. Allowed Values: `true` or `false`. +* `override_node_profile` - (Optional) The node profile override of the PTP Profile. This parameter is not applicable when `profile_template` is `telecom`. Allowed Values: `true` or `false`. +* `local_priority` - (Read-Only) The local priority of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Valid range: 1 to 128. +* `destination_mac_type` - (Read-Only) The destination MAC for PTP messages of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Allowed values are `forwardable` or `non_forwardable`. +* `mismatched_mac_handling` - (Read-Only) The mismatched destination MAC handling of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Allowed values are `drop`, `reply_with_config_mac` or `reply_with_received_mac`. ## Attribute Reference ## From 88dbe2bd28116128718d8e263dfb2141b0e7b641 Mon Sep 17 00:00:00 2001 From: samitab Date: Thu, 19 Feb 2026 11:57:00 +1000 Subject: [PATCH 5/8] [ignore] Add implicit UUID reference for PTP policy in PTP profiles. --- .../fabric_policies_ptp_policy_profile/main.tf | 3 ++- ...e_mso_fabric_policies_ptp_policy_profile.go | 4 ++++ ..._fabric_policies_ptp_policy_profile_test.go | 7 ++----- ...e_mso_fabric_policies_ptp_policy_profile.go | 11 +++++++++++ ..._fabric_policies_ptp_policy_profile_test.go | 18 +++++++++++------- ...c_policies_ptp_policy_profile.html.markdown | 1 + ...c_policies_ptp_policy_profile.html.markdown | 6 ++++-- 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/examples/fabric_policies_ptp_policy_profile/main.tf b/examples/fabric_policies_ptp_policy_profile/main.tf index d2fb0bf7..60228df3 100644 --- a/examples/fabric_policies_ptp_policy_profile/main.tf +++ b/examples/fabric_policies_ptp_policy_profile/main.tf @@ -40,7 +40,8 @@ resource "mso_fabric_policies_ptp_policy" "ptp_policy" { # fabric policies ptp policy profile example resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { - template_id = mso_template.fabric_policy_template.id + template_id = mso_template.fabric_policy_template.id + ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "ptp_policy_profile" description = "Example description" delay_interval = -2 diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go index 10e728de..01dc43b5 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go @@ -20,6 +20,10 @@ func datasourceMSOPtpPolicyProfile() *schema.Resource { Type: schema.TypeString, Required: true, }, + "ptp_policy_uuid": { + Type: schema.TypeString, + Computed: true, + }, "description": { Type: schema.TypeString, Computed: true, diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go index 9c88422d..5cc9aa05 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go @@ -28,6 +28,7 @@ func TestAccMSOPtpPolicyProfileDataSource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "mismatched_mac_handling", "reply_with_config_mac"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "override_node_profile", "false"), resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "uuid"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "ptp_policy_uuid"), ), }, }, @@ -38,6 +39,7 @@ func testAccMSOPtpPolicyProfileConfig() string { return fmt.Sprintf(`%s resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { template_id = mso_template.template_fabric_policy.id + ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile" description = "Terraform test PTP Policy Profile" profile_template = "telecom" @@ -49,11 +51,6 @@ func testAccMSOPtpPolicyProfileConfig() string { destination_mac_type = "forwardable" mismatched_mac_handling = "reply_with_config_mac" override_node_profile = "false" - - # Explicit dependency on PTP Policy - depends_on = [ - mso_fabric_policies_ptp_policy.ptp_policy - ] }`, testAccMSOPtpPolicyConfigCreate()) } diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile.go b/mso/resource_mso_fabric_policies_ptp_policy_profile.go index 46088619..783e8466 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile.go @@ -28,6 +28,11 @@ func resourceMSOPtpPolicyProfile() *schema.Resource { ForceNew: true, Required: true, }, + "ptp_policy_uuid": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, "name": { Type: schema.TypeString, ForceNew: true, @@ -106,6 +111,11 @@ func setPtpPolicyProfileData(d *schema.ResourceData, msoClient *client.Client, t return err } + ptp_policy_uuid, ok := response.S("fabricPolicyTemplate", "template", "ptpPolicy", "uuid").Data().(string) + if !ok { + return fmt.Errorf("PTP Policy not found") + } + policy, err := GetPolicyByName(response, policyName, "fabricPolicyTemplate", "template", "ptpPolicy", "profiles") if err != nil { return err @@ -115,6 +125,7 @@ func setPtpPolicyProfileData(d *schema.ResourceData, msoClient *client.Client, t d.SetId(fmt.Sprintf("templateId/%s/ptpPolicyProfile/%s", templateId, name)) d.Set("template_id", templateId) d.Set("name", name) + d.Set("ptp_policy_uuid", ptp_policy_uuid) d.Set("description", models.StripQuotes(policy.S("description").String())) d.Set("uuid", models.StripQuotes(policy.S("uuid").String())) d.Set("delay_interval", policy.S("delayIntvl").Data().(float64)) diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go index 5fc1ebbb..2badbcf9 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go @@ -24,6 +24,7 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_timeout", "3"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "override_node_profile", "false"), resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "uuid"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "ptp_policy_uuid"), ), }, { @@ -39,6 +40,7 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_timeout", "10"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "override_node_profile", "true"), resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "uuid"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "ptp_policy_uuid"), ), }, { @@ -57,6 +59,7 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "mismatched_mac_handling", "reply_with_config_mac"), resource.TestCheckNoResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "override_node_profile"), resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "uuid"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "ptp_policy_uuid"), ), }, { @@ -75,6 +78,7 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "mismatched_mac_handling", "reply_with_received_mac"), resource.TestCheckNoResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "override_node_profile"), resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "uuid"), + resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "ptp_policy_uuid"), ), }, { @@ -92,6 +96,7 @@ func testAccMSOPtpPolicyProfileConfigCreate() string { return fmt.Sprintf(`%s resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { template_id = mso_template.template_fabric_policy.id + ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile" description = "Terraform test PTP Policy Profile" profile_template = "aes67" @@ -112,6 +117,7 @@ func testAccMSOPtpPolicyProfileConfigUpdate() string { return fmt.Sprintf(`%s resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { template_id = mso_template.template_fabric_policy.id + ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile" description = "Terraform test PTP Policy Profile updated" profile_template = "smpte" @@ -132,6 +138,7 @@ func testAccMSOPtpPolicyProfileConfigCreateTelecom() string { return fmt.Sprintf(`%s resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile_2" { template_id = mso_template.template_fabric_policy.id + ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile_2" description = "Terraform test PTP Policy Profile 2" profile_template = "telecom" @@ -142,11 +149,6 @@ func testAccMSOPtpPolicyProfileConfigCreateTelecom() string { local_priority = 120 destination_mac_type = "forwardable" mismatched_mac_handling = "reply_with_config_mac" - - # Explicit dependency on PTP Policy - depends_on = [ - mso_fabric_policies_ptp_policy.ptp_policy - ] }`, testAccMSOPtpPolicyProfileConfigUpdate()) } @@ -154,6 +156,7 @@ func testAccMSOPtpPolicyProfileConfigUpdateTelecom() string { return fmt.Sprintf(`%s resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile_2" { template_id = mso_template.template_fabric_policy.id + ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile_2" description = "Terraform test PTP Policy Profile 2" profile_template = "telecom" @@ -165,9 +168,10 @@ func testAccMSOPtpPolicyProfileConfigUpdateTelecom() string { destination_mac_type = "non_forwardable" mismatched_mac_handling = "reply_with_received_mac" - # Explicit dependency on PTP Policy + # Explicit dependency on first PTP Profile + # This is to ensure the test deletes the profiles in order. depends_on = [ - mso_fabric_policies_ptp_policy.ptp_policy + mso_fabric_policies_ptp_policy_profile.ptp_policy_profile ] }`, testAccMSOPtpPolicyProfileConfigUpdate()) } diff --git a/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown b/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown index 31f7b139..afc45a6a 100644 --- a/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown +++ b/website/docs/d/fabric_policies_ptp_policy_profile.html.markdown @@ -31,6 +31,7 @@ data "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { ## Attribute Reference ## * `uuid` - (Read-Only) The NDO UUID of the PTP Profile. +* `ptp_policy_uuid` - (Read-Only) The NDO UUID of the PTP Policy. * `id` - (Read-Only) The unique Terraform identifier of the PTP Profile. * `description` - (Read-Only) The description of the PTP Profile. * `delay_interval` - (Read-Only) The delay interval of the PTP Profile. diff --git a/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown b/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown index 0a5b45a7..48c5e7e3 100644 --- a/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown +++ b/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown @@ -19,6 +19,7 @@ Manages (Precision Time Protocol) PTP Policy Profiles on Cisco Nexus Dashboard O ```hcl resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { template_id = mso_template.fabric_policy_template.id + ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "ptp_policy_profile" description = "Example description" delay_interval = -2 @@ -33,6 +34,7 @@ resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { ## Argument Reference ## * `template_id` - (Required) The unique ID of the Fabric Policy template. +* `ptp_policy_uuid` - (Required) The NDO UUID of the PTP Policy. * `name` - (Required) The name of the PTP Profile. * `description` - (Optional) The description of the PTP Profile. * `profile_template` - (Required) The profile template of the PTP Profile. Allowed values are `default`, `aes67`, `smpte` or `telecom`. @@ -52,8 +54,8 @@ resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { ## Importing ## -An existing MSO PTP Policy can be [imported][docs-import] into this resource via its ID/path, via the following command: [docs-import]: +An existing MSO PTP Profile can be [imported][docs-import] into this resource via its ID/path, via the following command: [docs-import]: ```bash -terraform import mso_fabric_policies_ptp_policy_profile.ptp_policy templateId/{template_id}/ptpPolicyProfile/{name} +terraform import mso_fabric_policies_ptp_policy_profile.ptp_policy_profile templateId/{template_id}/ptpPolicyProfile/{name} ``` From 36328bf18fc6a44bbe3ae26ee6087a8f5e0eb28c Mon Sep 17 00:00:00 2001 From: samitab Date: Mon, 23 Feb 2026 23:04:49 +1000 Subject: [PATCH 6/8] [ignore] Fix global_priority ranges. --- mso/resource_mso_fabric_policies_ptp_policy.go | 2 +- mso/resource_mso_fabric_policies_ptp_policy_profile.go | 4 ++-- website/docs/r/fabric_policies_ptp_policy.html.markdown | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mso/resource_mso_fabric_policies_ptp_policy.go b/mso/resource_mso_fabric_policies_ptp_policy.go index 6ac847bc..0410c9bb 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy.go +++ b/mso/resource_mso_fabric_policies_ptp_policy.go @@ -60,7 +60,7 @@ func resourceMSOPtpPolicy() *schema.Resource { "global_priority1": { Type: schema.TypeInt, Required: true, - ValidateFunc: validation.IntBetween(0, 255), + ValidateFunc: validation.IntBetween(1, 255), }, "global_priority2": { Type: schema.TypeInt, diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile.go b/mso/resource_mso_fabric_policies_ptp_policy_profile.go index 783e8466..47a69c0a 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile.go @@ -29,7 +29,7 @@ func resourceMSOPtpPolicyProfile() *schema.Resource { Required: true, }, "ptp_policy_uuid": { - Type: schema.TypeString, + Type: schema.TypeString, Required: true, ForceNew: true, }, @@ -115,7 +115,7 @@ func setPtpPolicyProfileData(d *schema.ResourceData, msoClient *client.Client, t if !ok { return fmt.Errorf("PTP Policy not found") } - + policy, err := GetPolicyByName(response, policyName, "fabricPolicyTemplate", "template", "ptpPolicy", "profiles") if err != nil { return err diff --git a/website/docs/r/fabric_policies_ptp_policy.html.markdown b/website/docs/r/fabric_policies_ptp_policy.html.markdown index ca0d17fc..662f322d 100644 --- a/website/docs/r/fabric_policies_ptp_policy.html.markdown +++ b/website/docs/r/fabric_policies_ptp_policy.html.markdown @@ -40,7 +40,7 @@ resource "mso_fabric_policies_ptp_policy" "ptp_policy" { * `description` - (Optional) The description of the PTP Policy. * `admin_state` - (Required) The administrative state of the PTP Policy. Allowed values are `enabled` or `disabled`. * `global_priority1` - (Required) The global priority1 of the PTP Policy. Valid range: 1-255. -* `global_priority2` - (Required) The global priority2 of the PTP Policy. Valid range: 1-255. +* `global_priority2` - (Required) The global priority2 of the PTP Policy. Valid range: 0-255. * `global_domain` - (Required) The global domain of the PTP Policy. Valid range: 0-128. * `fabric_profile_template` - (Required) The fabric profile template of the PTP Policy. Allowed values are `default`, `aes67`, or `smpte`. * `fabric_announce_interval` - (Required) The fabric announce interval in log base 2 seconds of the PTP Policy. Valid range: -3 to 4. From a0cffa10a76d59426d82a967ca7d965b7737a9bc Mon Sep 17 00:00:00 2001 From: samitab Date: Sun, 8 Mar 2026 22:39:57 +1000 Subject: [PATCH 7/8] [ignore] Fix resource doc --- .../docs/r/fabric_policies_ptp_policy_profile.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown b/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown index 48c5e7e3..294cf833 100644 --- a/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown +++ b/website/docs/r/fabric_policies_ptp_policy_profile.html.markdown @@ -43,9 +43,9 @@ resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { * `announce_interval` - (Required) The announce interval in log base 2 seconds of the PTP Profile. Valid range: -3 to 4. * `sync_interval` - (Required) The sync interval in log base 2 seconds of the PTP Profile.Valid range: -4 to 1. * `override_node_profile` - (Optional) The node profile override of the PTP Profile. This parameter is not applicable when `profile_template` is `telecom`. Allowed Values: `true` or `false`. -* `local_priority` - (Read-Only) The local priority of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Valid range: 1 to 128. -* `destination_mac_type` - (Read-Only) The destination MAC for PTP messages of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Allowed values are `forwardable` or `non_forwardable`. -* `mismatched_mac_handling` - (Read-Only) The mismatched destination MAC handling of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Allowed values are `drop`, `reply_with_config_mac` or `reply_with_received_mac`. +* `local_priority` - (Optional) The local priority of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Valid range: 1 to 128. +* `destination_mac_type` - (Optional) The destination MAC for PTP messages of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Allowed values are `forwardable` or `non_forwardable`. +* `mismatched_mac_handling` - (Optional) The mismatched destination MAC handling of the PTP Profile. This parameter is only applicable when `profile_template` is `telecom`. Allowed values are `drop`, `reply_with_config_mac` or `reply_with_received_mac`. ## Attribute Reference ## From cdd885e5e7e5ed5521f90aa235e90adbc8fe8856 Mon Sep 17 00:00:00 2001 From: samitab Date: Fri, 27 Mar 2026 09:03:25 +1000 Subject: [PATCH 8/8] [ignore] Removed ForceNew and name and allow descriptions to be cleared. --- ..._mso_fabric_policies_ptp_policy_profile.go | 4 ---- ...fabric_policies_ptp_policy_profile_test.go | 2 -- ...resource_mso_fabric_policies_ptp_policy.go | 2 -- ..._mso_fabric_policies_ptp_policy_profile.go | 18 --------------- ...fabric_policies_ptp_policy_profile_test.go | 22 ++----------------- ...rce_mso_fabric_policies_ptp_policy_test.go | 12 +++++----- .../fabric_policies_ptp_policy.html.markdown | 2 +- 7 files changed, 9 insertions(+), 53 deletions(-) diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go index 01dc43b5..42a11188 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile.go @@ -24,10 +24,6 @@ func datasourceMSOPtpPolicyProfile() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "description": { - Type: schema.TypeString, - Computed: true, - }, "uuid": { Type: schema.TypeString, Computed: true, diff --git a/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go index 5cc9aa05..34e66da6 100644 --- a/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go +++ b/mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go @@ -17,7 +17,6 @@ func TestAccMSOPtpPolicyProfileDataSource(t *testing.T) { Config: testAccMSOPtpPolicyProfileDataSource(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "description", "Terraform test PTP Policy Profile"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "telecom"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-4"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-4"), @@ -41,7 +40,6 @@ func testAccMSOPtpPolicyProfileConfig() string { template_id = mso_template.template_fabric_policy.id ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile" - description = "Terraform test PTP Policy Profile" profile_template = "telecom" announce_interval = -3 delay_interval = -4 diff --git a/mso/resource_mso_fabric_policies_ptp_policy.go b/mso/resource_mso_fabric_policies_ptp_policy.go index 0410c9bb..9143541e 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy.go +++ b/mso/resource_mso_fabric_policies_ptp_policy.go @@ -30,14 +30,12 @@ func resourceMSOPtpPolicy() *schema.Resource { }, "name": { Type: schema.TypeString, - ForceNew: true, Required: true, ValidateFunc: validation.StringLenBetween(1, 64), }, "description": { Type: schema.TypeString, Optional: true, - Computed: true, }, "uuid": { Type: schema.TypeString, diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile.go b/mso/resource_mso_fabric_policies_ptp_policy_profile.go index 47a69c0a..ddc666ad 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile.go @@ -35,15 +35,9 @@ func resourceMSOPtpPolicyProfile() *schema.Resource { }, "name": { Type: schema.TypeString, - ForceNew: true, Required: true, ValidateFunc: validation.StringLenBetween(1, 16), }, - "description": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, "uuid": { Type: schema.TypeString, Computed: true, @@ -126,7 +120,6 @@ func setPtpPolicyProfileData(d *schema.ResourceData, msoClient *client.Client, t d.Set("template_id", templateId) d.Set("name", name) d.Set("ptp_policy_uuid", ptp_policy_uuid) - d.Set("description", models.StripQuotes(policy.S("description").String())) d.Set("uuid", models.StripQuotes(policy.S("uuid").String())) d.Set("delay_interval", policy.S("delayIntvl").Data().(float64)) d.Set("sync_interval", policy.S("syncIntvl").Data().(float64)) @@ -176,10 +169,6 @@ func resourceMSOPtpPolicyProfileCreate(d *schema.ResourceData, m any) error { payload["name"] = d.Get("name").(string) - if description, ok := d.GetOk("description"); ok { - payload["description"] = description.(string) - } - if profile_template, ok := d.GetOk("profile_template"); ok { payload["profileTemplate"] = convertValueWithMap(profile_template.(string), ptpProfileTemplateMap) } @@ -269,13 +258,6 @@ func resourceMSOPtpPolicyProfileUpdate(d *schema.ResourceData, m any) error { } } - if d.HasChange("description") { - err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/description", updatePath), d.Get("description").(string)) - if err != nil { - return err - } - } - if d.HasChange("profile_template") { err := addPatchPayloadToContainer(payloadCont, "replace", fmt.Sprintf("%s/profileTemplate", updatePath), convertValueWithMap(d.Get("profile_template").(string), ptpProfileTemplateMap)) if err != nil { diff --git a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go index 2badbcf9..01af2c1f 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_profile_test.go @@ -16,7 +16,6 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { Config: testAccMSOPtpPolicyProfileConfigCreate(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "description", "Terraform test PTP Policy Profile"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "aes67"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-2"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-3"), @@ -31,8 +30,7 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { PreConfig: func() { fmt.Println("Test: Update PTP Policy Profile") }, Config: testAccMSOPtpPolicyProfileConfigUpdate(), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "description", "Terraform test PTP Policy Profile updated"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile_1"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "smpte"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-2"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-2"), @@ -48,7 +46,6 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { Config: testAccMSOPtpPolicyProfileConfigCreateTelecom(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "name", "tf_ptp_profile_2"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "description", "Terraform test PTP Policy Profile 2"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "profile_template", "telecom"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "delay_interval", "-4"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "sync_interval", "-4"), @@ -67,7 +64,6 @@ func TestAccMSOPtpPolicyProfileResource(t *testing.T) { Config: testAccMSOPtpPolicyProfileConfigUpdateTelecom(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "name", "tf_ptp_profile_2"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "description", "Terraform test PTP Policy Profile 2"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "profile_template", "telecom"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "delay_interval", "-4"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile_2", "sync_interval", "-4"), @@ -98,18 +94,12 @@ func testAccMSOPtpPolicyProfileConfigCreate() string { template_id = mso_template.template_fabric_policy.id ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile" - description = "Terraform test PTP Policy Profile" profile_template = "aes67" delay_interval = -2 sync_interval = -3 announce_timeout = 3 announce_interval = 1 override_node_profile = false - - # Explicit dependency on PTP Policy - depends_on = [ - mso_fabric_policies_ptp_policy.ptp_policy - ] }`, testAccMSOPtpPolicyConfigCreate()) } @@ -118,19 +108,13 @@ func testAccMSOPtpPolicyProfileConfigUpdate() string { resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" { template_id = mso_template.template_fabric_policy.id ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid - name = "tf_ptp_profile" - description = "Terraform test PTP Policy Profile updated" + name = "tf_ptp_profile_1" profile_template = "smpte" delay_interval = -2 sync_interval = -2 announce_timeout = 10 announce_interval = -3 override_node_profile = true - - # Explicit dependency on PTP Policy - depends_on = [ - mso_fabric_policies_ptp_policy.ptp_policy - ] }`, testAccMSOPtpPolicyConfigCreate()) } @@ -140,7 +124,6 @@ func testAccMSOPtpPolicyProfileConfigCreateTelecom() string { template_id = mso_template.template_fabric_policy.id ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile_2" - description = "Terraform test PTP Policy Profile 2" profile_template = "telecom" announce_interval = -3 delay_interval = -4 @@ -158,7 +141,6 @@ func testAccMSOPtpPolicyProfileConfigUpdateTelecom() string { template_id = mso_template.template_fabric_policy.id ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid name = "tf_ptp_profile_2" - description = "Terraform test PTP Policy Profile 2" profile_template = "telecom" announce_interval = -3 delay_interval = -4 diff --git a/mso/resource_mso_fabric_policies_ptp_policy_test.go b/mso/resource_mso_fabric_policies_ptp_policy_test.go index 427baa76..a4fc56a0 100644 --- a/mso/resource_mso_fabric_policies_ptp_policy_test.go +++ b/mso/resource_mso_fabric_policies_ptp_policy_test.go @@ -33,8 +33,8 @@ func TestAccMSOPtpPolicyResource(t *testing.T) { PreConfig: func() { fmt.Println("Test: Update PTP Policy disabled state") }, Config: testAccMSOPtpPolicyConfigUpdateDisable(), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"), - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy disabled"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy_new"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", ""), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "disabled"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "default"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority1", "255"), @@ -51,7 +51,7 @@ func TestAccMSOPtpPolicyResource(t *testing.T) { PreConfig: func() { fmt.Println("Test: Update PTP Policy changing the profile template") }, Config: testAccMSOPtpPolicyConfigUpdateChangingTemplate(), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"), + resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy_new"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "enabled"), resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "smpte"), @@ -98,8 +98,8 @@ func testAccMSOPtpPolicyConfigUpdateDisable() string { return fmt.Sprintf(`%s resource "mso_fabric_policies_ptp_policy" "ptp_policy" { template_id = mso_template.template_fabric_policy.id - name = "tf_test_ptp_policy" - description = "Terraform test PTP Policy disabled" + name = "tf_test_ptp_policy_new" + description = "" admin_state = "disabled" fabric_profile_template = "default" global_priority1 = 255 @@ -116,7 +116,7 @@ func testAccMSOPtpPolicyConfigUpdateChangingTemplate() string { return fmt.Sprintf(`%s resource "mso_fabric_policies_ptp_policy" "ptp_policy" { template_id = mso_template.template_fabric_policy.id - name = "tf_test_ptp_policy" + name = "tf_test_ptp_policy_new" description = "Terraform test PTP Policy" admin_state = "enabled" fabric_profile_template = "smpte" diff --git a/website/docs/r/fabric_policies_ptp_policy.html.markdown b/website/docs/r/fabric_policies_ptp_policy.html.markdown index 662f322d..5f2a5d01 100644 --- a/website/docs/r/fabric_policies_ptp_policy.html.markdown +++ b/website/docs/r/fabric_policies_ptp_policy.html.markdown @@ -37,7 +37,7 @@ resource "mso_fabric_policies_ptp_policy" "ptp_policy" { * `template_id` - (Required) The unique ID of the Fabric Policy template. * `name` - (Required) The name of the PTP Policy. -* `description` - (Optional) The description of the PTP Policy. +* `description` - (Optional) The description of the PTP Policy. If this argument is omitted, the value defaults to an empty string (`""`). * `admin_state` - (Required) The administrative state of the PTP Policy. Allowed values are `enabled` or `disabled`. * `global_priority1` - (Required) The global priority1 of the PTP Policy. Valid range: 1-255. * `global_priority2` - (Required) The global priority2 of the PTP Policy. Valid range: 0-255.