Skip to content

Commit

Permalink
Merge pull request #6 from CiscoDevNet/destroy-child
Browse files Browse the repository at this point in the history
delete method of child resources updated
  • Loading branch information
nkatarmal-crest authored Dec 23, 2020
2 parents 88d9447 + ec91aa1 commit fde4816
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 62 deletions.
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_site_anp_epg_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ func resourceMSOSchemaSiteAnpEpgDomainDelete(d *schema.ResourceData, m interface
return err
}
if index == -1 {
fmt.Errorf("The given Anp Epg Domain is not found")
d.SetId("")
return nil
}
indexs := strconv.Itoa(index)

Expand Down
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_site_anp_epg_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ func resourceSchemaSiteApnEpgSelectorDelete(d *schema.ResourceData, m interface{
return err
}
if indexGet == -1 {
return fmt.Errorf("No selectors found")
d.SetId("")
return nil
}

path := fmt.Sprintf("/sites/%s-%s/anps/%s/epgs/%s/selectors/%v", siteID, template, anpName, epgName, indexGet)
Expand Down
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_site_anp_epg_static_leaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ func resourceMSOSchemaSiteAnpEpgStaticleafDelete(d *schema.ResourceData, m inter
}

if index == -1 {
return fmt.Errorf("The given staticLeaf is not found")
d.SetId("")
return nil
}

indexs := strconv.Itoa(index)
Expand Down
5 changes: 0 additions & 5 deletions mso/resource_mso_schema_site_anp_epg_static_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ func resourceMSOSchemaSiteAnpEpgStaticPortDelete(d *schema.ResourceData, m inter
if err != nil {
return fmt.Errorf("No Sites found")
}
found := false

var pathType, pod, leaf, path, deploymentImmediacy, mode, fex string
var vlan, microsegvlan int
Expand Down Expand Up @@ -670,7 +669,6 @@ func resourceMSOSchemaSiteAnpEpgStaticPortDelete(d *schema.ResourceData, m inter
if err != nil {
return err
}
found = true
break
}
}
Expand All @@ -681,9 +679,6 @@ func resourceMSOSchemaSiteAnpEpgStaticPortDelete(d *schema.ResourceData, m inter
}
}
}
if !found {
return fmt.Errorf("The specified parameters to delete the static port entry not found")
}
d.SetId("")
return resourceMSOSchemaSiteAnpEpgStaticPortRead(d, m)
}
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_site_bd_l3out.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ func resourceMSOSchemaSiteBdL3outDelete(d *schema.ResourceData, m interface{}) e
return err
}
if index == -1 {
fmt.Errorf("The given Anp Epg Domain is not found")
d.SetId("")
return nil
}
indexs := strconv.Itoa(index)

Expand Down
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_site_external_epg_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ func resourceMSOSchemaSiteExternalEpgSelectorDelete(d *schema.ResourceData, m in
return err
}
if index == -1 {
return fmt.Errorf("No Selector found")
d.SetId("")
return nil
}

path := fmt.Sprintf("/sites/%s-%s/externalEpgs/%s/subnets/%v", siteID, templateName, extrEpgName, index)
Expand Down
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_site_vrf_region_cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ func resourceMSOSchemaSiteVrfRegionCidrDelete(d *schema.ResourceData, m interfac
return err
}
if index == -1 {
return fmt.Errorf("The given Vrf Region Cidr is not found")
d.SetId("")
return nil
}
indexs := strconv.Itoa(index)

Expand Down
5 changes: 5 additions & 0 deletions mso/resource_mso_schema_site_vrf_region_cidr_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ func resourceMSOSchemaSiteVrfRegionCidrSubnetDelete(d *schema.ResourceData, m in
}
}

if index == -1 {
d.SetId("")
return nil
}

path := fmt.Sprintf("/sites/%s-%s/vrfs/%s/regions/%s/cidrs/%v/subnets/%v", siteId, templateName, vrfName, regionName, cindex, index)
vrfRegionStruct := models.NewSchemaSiteVrfRegionCidrSubnet("remove", path, ip, zone, usage)

Expand Down
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_template_anp_epg_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ func resourceMSOTemplateAnpEpgContractDelete(d *schema.ResourceData, m interface
return err
}
if index == -1 {
fmt.Errorf("The given contract id is not found")
d.SetId("")
return nil
}
indexs := strconv.Itoa(index)

Expand Down
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_template_anp_epg_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ func resourceMSOSchemaTemplateAnpEpgSubnetDelete(d *schema.ResourceData, m inter
return err
}
if index == -1 {
fmt.Errorf("The given subnet ip is not found")
d.SetId("")
return nil
}
indexs := strconv.Itoa(index)
schemaTemplateAnpEpgSubnetApp := models.NewSchemaTemplateAnpEpgSubnet("remove", "/templates/"+template+"/anps/"+anpName+"/epgs/"+epgName+"/subnets/"+indexs, "", "", false)
Expand Down
5 changes: 0 additions & 5 deletions mso/resource_mso_schema_template_bd_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ func resourceMSOTemplateBDSubnetDelete(d *schema.ResourceData, m interface{}) er
return fmt.Errorf("No Template found")
}
stateTemplate := d.Get("template_name").(string)
found := false
stateBD := d.Get("bd_name")
stateIP := d.Get("ip")
for i := 0; i < count; i++ {
Expand Down Expand Up @@ -389,17 +388,13 @@ func resourceMSOTemplateBDSubnetDelete(d *schema.ResourceData, m interface{}) er
if err != nil {
return err
}
found = true
break
}
}
}
}
}
}
if !found {
return fmt.Errorf("The specified parameters are incorrect for delete operation")
}
d.SetId("")
return nil
}
7 changes: 0 additions & 7 deletions mso/resource_mso_schema_template_contract_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ func resourceMSOTemplateContractFilterDelete(d *schema.ResourceData, m interface
indexf := 0
indexfp := 0
indexfc := 0
found := false
cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID))
if err != nil {
return err
Expand Down Expand Up @@ -604,7 +603,6 @@ func resourceMSOTemplateContractFilterDelete(d *schema.ResourceData, m interface
filRef := filterCont.S("filterRef").Data()
split := strings.Split(filRef.(string), "/")
if split[6] == filterName && split[4] == filterTemplate && split[2] == filterId {
found = true
paths := fmt.Sprintf("/templates/%s/contracts/%s/filterRelationships/%v", templateName, contractName, k)
contract := models.NewTemplateContractFilterRelationShip("remove", paths, filterRefMap, directives)
_, err1 := msoClient.PatchbyID(fmt.Sprintf("api/v1/schemas/%s", schemaID), contract)
Expand All @@ -628,7 +626,6 @@ func resourceMSOTemplateContractFilterDelete(d *schema.ResourceData, m interface
filRef := filterCont.S("filterRef").Data()
split := strings.Split(filRef.(string), "/")
if split[6] == filterName && split[4] == filterTemplate && split[2] == filterId {
found = true

paths := fmt.Sprintf("/templates/%s/contracts/%s/filterRelationshipsProviderToConsumer/%v", templateName, contractName, k)
contract := models.NewTemplateContractFilterRelationShip("remove", paths, filterRefMap, directives)
Expand Down Expand Up @@ -656,7 +653,6 @@ func resourceMSOTemplateContractFilterDelete(d *schema.ResourceData, m interface
filRef := filterCont.S("filterRef").Data()
split := strings.Split(filRef.(string), "/")
if split[6] == filterName && split[4] == filterTemplate && split[2] == filterId {
found = true
paths := fmt.Sprintf("/templates/%s/contracts/%s/filterRelationshipsConsumerToProvider/%v", templateName, contractName, k)
contract := models.NewTemplateContractFilterRelationShip("remove", paths, filterRefMap, directives)
_, err1 := msoClient.PatchbyID(fmt.Sprintf("api/v1/schemas/%s", schemaID), contract)
Expand All @@ -677,9 +673,6 @@ func resourceMSOTemplateContractFilterDelete(d *schema.ResourceData, m interface
}
}
}
if !found {
return fmt.Errorf("Unable to find given Contract Filter")
}
return resourceMSOTemplateContractFilterRead(d, m)

}
10 changes: 5 additions & 5 deletions mso/resource_mso_schema_template_external_epg_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ func resourceMSOTemplateExternalEpgContractDelete(d *schema.ResourceData, m inte
return err
}

if index == -1 {
d.SetId("")
return nil
}

indexs := strconv.Itoa(index)

path := fmt.Sprintf("/templates/%s/externalEpgs/%s/contractRelationships/%s", templateName, epgName, indexs)
Expand All @@ -265,7 +270,6 @@ func resourceMSOTemplateExternalEpgContractDelete(d *schema.ResourceData, m inte
return nil
}
func fetchIndexs(cont *container.Container, templateName, epgName, contractName string) (int, error) {
found := false
index := -1
count, err := cont.ArrayCount("templates")
if err != nil {
Expand Down Expand Up @@ -304,7 +308,6 @@ func fetchIndexs(cont *container.Container, templateName, epgName, contractName
re := regexp.MustCompile("/schemas/(.*)/templates/(.*)/contracts/(.*)")
split := re.FindStringSubmatch(contractRef)
if contractName == fmt.Sprintf("%s", split[3]) {
found = true
index = k
break
}
Expand All @@ -313,9 +316,6 @@ func fetchIndexs(cont *container.Container, templateName, epgName, contractName
}
}
}
if !found {
return index, fmt.Errorf("Unable to Find the external Epg Contract")
}

return index, nil
}
3 changes: 2 additions & 1 deletion mso/resource_mso_schema_template_external_epg_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ func resourceMSOTemplateExtenalepgSubnetDelete(d *schema.ResourceData, m interfa
return err
}
if index == -1 {
fmt.Errorf("The given subnet ip is not found")
d.SetId("")
return nil
}
indexs := strconv.Itoa(index)

Expand Down
Loading

0 comments on commit fde4816

Please sign in to comment.