@@ -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 ("" )
0 commit comments