From f3700674f84b5415e2ab7686559bedfff34a7c9e Mon Sep 17 00:00:00 2001 From: anvitha-jain Date: Thu, 11 Jul 2024 15:09:40 -0700 Subject: [PATCH] [minor_changes] Added additional check to avoid error generation for checks only required for cloud servicegraphs. --- mso/resource_mso_schema_site_service_graph.go | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/mso/resource_mso_schema_site_service_graph.go b/mso/resource_mso_schema_site_service_graph.go index d747a79a..8f3ab756 100644 --- a/mso/resource_mso_schema_site_service_graph.go +++ b/mso/resource_mso_schema_site_service_graph.go @@ -112,38 +112,43 @@ func resourceMSOSchemaSiteServiceGraph() *schema.Resource { } sgCont, _, err := getTemplateServiceGraphCont(cont, templateName.(string), graphName.(string)) - if err != nil { + if strings.Contains(fmt.Sprint(err), "No Template found") { + // The function getTemplateServiceGraphCont() is not required when the template is attched to physical site. + return nil + } else if err != nil { log.Printf("graphcont err %v", err) return err - } - - var templateServiceNodeList []string - serviceNodes := sgCont.S("serviceNodes").Data().([]interface{}) - for _, val := range serviceNodes { - serviceNodeValues := val.(map[string]interface{}) - nodeId := models.StripQuotes(serviceNodeValues["serviceNodeTypeId"].(string)) - - nodeType, err := getNodeNameFromId(msoClient, nodeId) - if err != nil { - return err + } else { + /* The function getTemplateServiceGraphCont() is required when the template is attached to cloud sites. + provider_connector_type is applicable only for cloud sites. */ + var templateServiceNodeList []string + serviceNodes := sgCont.S("serviceNodes").Data().([]interface{}) + for _, val := range serviceNodes { + serviceNodeValues := val.(map[string]interface{}) + nodeId := models.StripQuotes(serviceNodeValues["serviceNodeTypeId"].(string)) + + nodeType, err := getNodeNameFromId(msoClient, nodeId) + if err != nil { + return err + } + + templateServiceNodeList = append(templateServiceNodeList, nodeType) } - templateServiceNodeList = append(templateServiceNodeList, nodeType) - } - - /* Loop trough the templateServiceNodeList and validate the site level user input(provider_connector_type) - to verify it's value for nodetype 'other' and 'firewall'. */ - _, siteServiceNodes := diff.GetChange("service_node") - - for i, val := range siteServiceNodes.([]interface{}) { - serviceNode := val.(map[string]interface{}) - if templateServiceNodeList[i] == "other" && !valueInSliceofStrings(serviceNode["provider_connector_type"].(string), []string{"none", "redir"}) { - return fmt.Errorf("The expected value for service_node.%d.provider_connector_type have to be one of [none, redir] when template's service node type is other, got %s.", i, serviceNode["provider_connector_type"]) - } else if templateServiceNodeList[i] == "firewall" && !valueInSliceofStrings(serviceNode["provider_connector_type"].(string), []string{"none", "redir", "snat", "dnat", "snat_dnat"}) { - return fmt.Errorf("The expected value for service_node.%d.provider_connector_type have to be one of [none, redir, snat, dnat, snat_dnat] when template's service node type is firewall, got %s.", i, serviceNode["provider_connector_type"]) + /* Loop trough the templateServiceNodeList and validate the site level user input(provider_connector_type) + to verify it's value for nodetype 'other' and 'firewall'. */ + _, siteServiceNodes := diff.GetChange("service_node") + + for i, val := range siteServiceNodes.([]interface{}) { + serviceNode := val.(map[string]interface{}) + if templateServiceNodeList[i] == "other" && !valueInSliceofStrings(serviceNode["provider_connector_type"].(string), []string{"none", "redir"}) { + return fmt.Errorf("The expected value for service_node.%d.provider_connector_type have to be one of [none, redir] when template's service node type is other, got %s.", i, serviceNode["provider_connector_type"]) + } else if templateServiceNodeList[i] == "firewall" && !valueInSliceofStrings(serviceNode["provider_connector_type"].(string), []string{"none", "redir", "snat", "dnat", "snat_dnat"}) { + return fmt.Errorf("The expected value for service_node.%d.provider_connector_type have to be one of [none, redir, snat, dnat, snat_dnat] when template's service node type is firewall, got %s.", i, serviceNode["provider_connector_type"]) + } } + return nil } - return nil }, } }