Skip to content

Commit 28428d4

Browse files
AshuSoni-crestlhercot
authored andcommitted
updated bgpPeerP to dynamically create object of bgpAsnP and bgpLocalAsnP
1 parent 84f82fb commit 28428d4

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

aci/resource_aci_bgppeerp.go

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ func resourceAciBgpPeerConnectivityProfile() *schema.Resource {
133133
},
134134

135135
"local_asn_propagate": &schema.Schema{
136-
Type: schema.TypeString,
137-
Optional: true,
138-
Computed: true,
136+
Type: schema.TypeString,
137+
Optional: true,
138+
Computed: true,
139+
RequiredWith: []string{"local_asn"},
140+
139141
ValidateFunc: validation.StringInSlice([]string{
140142
"dual-as",
141143
"no-prepend",
@@ -307,32 +309,37 @@ func resourceAciBgpPeerConnectivityProfileCreate(d *schema.ResourceData, m inter
307309
return err
308310
}
309311
PeerConnectivityProfileDn := bgpPeerP.DistinguishedName
310-
bgpLocalAsnPAttr := models.LocalAutonomousSystemProfileAttributes{}
311312

312-
if AsnPropagate, ok := d.GetOk("local_asn_propagate"); ok {
313-
bgpLocalAsnPAttr.AsnPropagate = AsnPropagate.(string)
314-
}
315-
if LocalAsn, ok := d.GetOk("local_asn"); ok {
316-
bgpLocalAsnPAttr.LocalAsn = LocalAsn.(string)
317-
}
313+
if _, ok := d.GetOk("local_asn"); ok {
314+
bgpLocalAsnPAttr := models.LocalAutonomousSystemProfileAttributes{}
318315

319-
bgpLocalAsnP := models.NewLocalAutonomousSystemProfile(fmt.Sprintf("localasn"), PeerConnectivityProfileDn, desc, bgpLocalAsnPAttr)
316+
if AsnPropagate, ok := d.GetOk("local_asn_propagate"); ok {
317+
bgpLocalAsnPAttr.AsnPropagate = AsnPropagate.(string)
318+
}
319+
if LocalAsn, ok := d.GetOk("local_asn"); ok {
320+
bgpLocalAsnPAttr.LocalAsn = LocalAsn.(string)
321+
}
320322

321-
err = aciClient.Save(bgpLocalAsnP)
322-
if err != nil {
323-
return err
323+
bgpLocalAsnP := models.NewLocalAutonomousSystemProfile(fmt.Sprintf("localasn"), PeerConnectivityProfileDn, desc, bgpLocalAsnPAttr)
324+
325+
err = aciClient.Save(bgpLocalAsnP)
326+
if err != nil {
327+
return err
328+
}
324329
}
325330

326-
bgpAsPAttr := models.BgpAutonomousSystemProfileAttributes{}
331+
if _, ok := d.GetOk("as_number"); ok {
332+
bgpAsPAttr := models.BgpAutonomousSystemProfileAttributes{}
327333

328-
if Asn, ok := d.GetOk("as_number"); ok {
329-
bgpAsPAttr.Asn = Asn.(string)
330-
}
334+
if Asn, ok := d.GetOk("as_number"); ok {
335+
bgpAsPAttr.Asn = Asn.(string)
336+
}
331337

332-
bgpAsP := models.NewBgpAutonomousSystemProfile(fmt.Sprintf("as"), PeerConnectivityProfileDn, desc, bgpAsPAttr)
333-
err = aciClient.Save(bgpAsP)
334-
if err != nil {
335-
return err
338+
bgpAsP := models.NewBgpAutonomousSystemProfile(fmt.Sprintf("as"), PeerConnectivityProfileDn, desc, bgpAsPAttr)
339+
err = aciClient.Save(bgpAsP)
340+
if err != nil {
341+
return err
342+
}
336343
}
337344

338345
d.Partial(true)
@@ -431,34 +438,36 @@ func resourceAciBgpPeerConnectivityProfileUpdate(d *schema.ResourceData, m inter
431438
}
432439

433440
PeerConnectivityProfileDn := bgpPeerP.DistinguishedName
434-
bgpLocalAsnPAttr := models.LocalAutonomousSystemProfileAttributes{}
441+
if _, ok := d.GetOk("local_asn"); ok {
442+
bgpLocalAsnPAttr := models.LocalAutonomousSystemProfileAttributes{}
435443

436-
if AsnPropagate, ok := d.GetOk("local_asn_propagate"); ok {
437-
bgpLocalAsnPAttr.AsnPropagate = AsnPropagate.(string)
438-
}
439-
if LocalAsn, ok := d.GetOk("local_asn"); ok {
440-
bgpLocalAsnPAttr.LocalAsn = LocalAsn.(string)
441-
}
444+
if AsnPropagate, ok := d.GetOk("local_asn_propagate"); ok {
445+
bgpLocalAsnPAttr.AsnPropagate = AsnPropagate.(string)
446+
}
447+
if LocalAsn, ok := d.GetOk("local_asn"); ok {
448+
bgpLocalAsnPAttr.LocalAsn = LocalAsn.(string)
449+
}
442450

443-
bgpLocalAsnP := models.NewLocalAutonomousSystemProfile(fmt.Sprintf("localasn"), PeerConnectivityProfileDn, desc, bgpLocalAsnPAttr)
444-
bgpLocalAsnP.Status = "modified"
451+
bgpLocalAsnP := models.NewLocalAutonomousSystemProfile(fmt.Sprintf("localasn"), PeerConnectivityProfileDn, desc, bgpLocalAsnPAttr)
445452

446-
err = aciClient.Save(bgpLocalAsnP)
447-
if err != nil {
448-
return err
453+
err = aciClient.Save(bgpLocalAsnP)
454+
if err != nil {
455+
return err
456+
}
449457
}
450458

451-
bgpAsPAttr := models.BgpAutonomousSystemProfileAttributes{}
459+
if _, ok := d.GetOk("as_number"); ok {
460+
bgpAsPAttr := models.BgpAutonomousSystemProfileAttributes{}
452461

453-
if Asn, ok := d.GetOk("as_number"); ok {
454-
bgpAsPAttr.Asn = Asn.(string)
455-
}
462+
if Asn, ok := d.GetOk("as_number"); ok {
463+
bgpAsPAttr.Asn = Asn.(string)
464+
}
456465

457-
bgpAsP := models.NewBgpAutonomousSystemProfile(fmt.Sprintf("as"), PeerConnectivityProfileDn, desc, bgpAsPAttr)
458-
bgpAsP.Status = "modified"
459-
err = aciClient.Save(bgpAsP)
460-
if err != nil {
461-
return err
466+
bgpAsP := models.NewBgpAutonomousSystemProfile(fmt.Sprintf("as"), PeerConnectivityProfileDn, desc, bgpAsPAttr)
467+
err = aciClient.Save(bgpAsP)
468+
if err != nil {
469+
return err
470+
}
462471
}
463472

464473
d.Partial(true)
@@ -515,17 +524,23 @@ func resourceAciBgpPeerConnectivityProfileRead(d *schema.ResourceData, m interfa
515524
}
516525
setBgpPeerConnectivityProfileAttributes(bgpPeerP, d)
517526

518-
bgpAsP, err := getRemoteBgpAutonomousSystemProfileFromBgpPeerConnectivityProfile(aciClient, fmt.Sprintf("%s/as", dn))
519-
if err != nil {
520-
return err
527+
if _, ok := d.GetOk("as_number"); ok {
528+
bgpAsP, err := getRemoteBgpAutonomousSystemProfileFromBgpPeerConnectivityProfile(aciClient, fmt.Sprintf("%s/as", dn))
529+
if err != nil {
530+
d.SetId("")
531+
return nil
532+
}
533+
setBgpAutonomousSystemProfileAttributesFromBgpPeerConnectivityProfile(bgpAsP, d)
521534
}
522-
setBgpAutonomousSystemProfileAttributesFromBgpPeerConnectivityProfile(bgpAsP, d)
523535

524-
bgpLocalAsnP, err := getRemoteLocalAutonomousSystemProfileFromBgpPeerConnectivityProfile(aciClient, fmt.Sprintf("%s/localasn", dn))
525-
if err != nil {
526-
return err
536+
if _, ok := d.GetOk("local_asn"); ok {
537+
bgpLocalAsnP, err := getRemoteLocalAutonomousSystemProfileFromBgpPeerConnectivityProfile(aciClient, fmt.Sprintf("%s/localasn", dn))
538+
if err != nil {
539+
d.SetId("")
540+
return nil
541+
}
542+
setLocalAutonomousSystemProfileAttributesFromBgpPeerConnectivityProfile(bgpLocalAsnP, d)
527543
}
528-
setLocalAutonomousSystemProfileAttributesFromBgpPeerConnectivityProfile(bgpLocalAsnP, d)
529544

530545
bgpRsPeerPfxPolData, err := aciClient.ReadRelationbgpRsPeerPfxPolFromBgpPeerConnectivityProfile(dn)
531546
if err != nil {
@@ -555,15 +570,7 @@ func resourceAciBgpPeerConnectivityProfileDelete(d *schema.ResourceData, m inter
555570
if err != nil {
556571
return err
557572
}
558-
err = aciClient.DeleteByDn(fmt.Sprintf("%s/localasn", dn), "bgpLocalAsnP")
559-
if err != nil {
560-
return err
561-
}
562-
err = aciClient.DeleteByDn(fmt.Sprintf("%s/as", dn), "bgpAsP")
563-
if err != nil {
564-
return err
565-
}
566-
573+
567574
log.Printf("[DEBUG] %s: Destroy finished successfully", d.Id())
568575

569576
d.SetId("")

website/docs/r/bgp_peer_connectivity_profile.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ resource "aci_bgp_peer_connectivity_profile" "example" {
5353
Allowed values: "remove-all", "remove-exclusive", "replace-as". Default value: "".
5454
- `ttl` - (Optional) Specifies time to live (TTL). Default value: "1".
5555
- `weight` - (Optional) The weight of the fault in calculating the health score of an object. A higher weight causes a higher degradation of the health score of the affected object. Default value: "0".
56-
- `as_number` - (Optional) A number that uniquely identifies an autonomous system. Default value: "0".
57-
- `local_asn ` - (Optional) The local autonomous system number (ASN). Default value: "0".
58-
- `local_asn_propagate` - (Optional) The local Autonomous System Number (ASN) configuration.
56+
- `as_number` - (Optional) A number that uniquely identifies an autonomous system.
57+
- `local_asn ` - (Optional) The local autonomous system number (ASN).
58+
- `local_asn_propagate` - (Optional) The local Autonomous System Number (ASN) configuration.
5959
Allowed values: "dual-as", "no-prepend", "none", "replace-as". Default value: "none".
6060
- `relation_bgp_rs_peer_pfx_pol` - (Optional) Relation to class bgpPeerPfxPol. Cardinality - N_TO_ONE. Type - String.
6161

0 commit comments

Comments
 (0)