@@ -136,6 +136,22 @@ type Route53API interface {
136136 ListTagsForResourceWithContext (ctx context.Context , input * route53.ListTagsForResourceInput , opts ... request.Option ) (* route53.ListTagsForResourceOutput , error )
137137}
138138
139+ // wrapper to handle ownership relation throughout the provider implementation
140+ type Route53Change struct {
141+ route53.Change
142+ OwnedRecord string
143+ }
144+
145+ type Route53Changes []* Route53Change
146+
147+ func (cs Route53Changes ) Route53Changes () []* route53.Change {
148+ ret := []* route53.Change {}
149+ for _ , c := range cs {
150+ ret = append (ret , & c .Change )
151+ }
152+ return ret
153+ }
154+
139155type zonesListCache struct {
140156 age time.Time
141157 duration time.Duration
@@ -467,7 +483,7 @@ func (p *AWSProvider) requiresDeleteCreate(old *endpoint.Endpoint, new *endpoint
467483 return false
468484}
469485
470- func (p * AWSProvider ) createUpdateChanges (newEndpoints , oldEndpoints []* endpoint.Endpoint ) [] * route53. Change {
486+ func (p * AWSProvider ) createUpdateChanges (newEndpoints , oldEndpoints []* endpoint.Endpoint ) Route53Changes {
471487 var deletes []* endpoint.Endpoint
472488 var creates []* endpoint.Endpoint
473489 var updates []* endpoint.Endpoint
@@ -483,7 +499,7 @@ func (p *AWSProvider) createUpdateChanges(newEndpoints, oldEndpoints []*endpoint
483499 }
484500 }
485501
486- combined := make ([] * route53. Change , 0 , len (deletes )+ len (creates )+ len (updates ))
502+ combined := make (Route53Changes , 0 , len (deletes )+ len (creates )+ len (updates ))
487503 combined = append (combined , p .newChanges (route53 .ChangeActionCreate , creates )... )
488504 combined = append (combined , p .newChanges (route53 .ChangeActionUpsert , updates )... )
489505 combined = append (combined , p .newChanges (route53 .ChangeActionDelete , deletes )... )
@@ -514,7 +530,7 @@ func (p *AWSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) e
514530
515531 updateChanges := p .createUpdateChanges (changes .UpdateNew , changes .UpdateOld )
516532
517- combinedChanges := make ([] * route53. Change , 0 , len (changes .Delete )+ len (changes .Create )+ len (updateChanges ))
533+ combinedChanges := make (Route53Changes , 0 , len (changes .Delete )+ len (changes .Create )+ len (updateChanges ))
518534 combinedChanges = append (combinedChanges , p .newChanges (route53 .ChangeActionCreate , changes .Create )... )
519535 combinedChanges = append (combinedChanges , p .newChanges (route53 .ChangeActionDelete , changes .Delete )... )
520536 combinedChanges = append (combinedChanges , updateChanges ... )
@@ -523,7 +539,7 @@ func (p *AWSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) e
523539}
524540
525541// submitChanges takes a zone and a collection of Changes and sends them as a single transaction.
526- func (p * AWSProvider ) submitChanges (ctx context.Context , changes [] * route53. Change , zones map [string ]* route53.HostedZone ) error {
542+ func (p * AWSProvider ) submitChanges (ctx context.Context , changes Route53Changes , zones map [string ]* route53.HostedZone ) error {
527543 // return early if there is nothing to change
528544 if len (changes ) == 0 {
529545 log .Info ("All records are already up to date" )
@@ -551,7 +567,7 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes []*route53.Chan
551567 params := & route53.ChangeResourceRecordSetsInput {
552568 HostedZoneId : aws .String (z ),
553569 ChangeBatch : & route53.ChangeBatch {
554- Changes : b ,
570+ Changes : b . Route53Changes () ,
555571 },
556572 }
557573
@@ -583,16 +599,16 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes []*route53.Chan
583599}
584600
585601// newChanges returns a collection of Changes based on the given records and action.
586- func (p * AWSProvider ) newChanges (action string , endpoints []* endpoint.Endpoint ) [] * route53. Change {
587- changes := make ([] * route53. Change , 0 , len (endpoints ))
602+ func (p * AWSProvider ) newChanges (action string , endpoints []* endpoint.Endpoint ) Route53Changes {
603+ changes := make (Route53Changes , 0 , len (endpoints ))
588604
589605 for _ , endpoint := range endpoints {
590606 change , dualstack := p .newChange (action , endpoint )
591607 changes = append (changes , change )
592608 if dualstack {
593609 // make a copy of change, modify RRS type to AAAA, then add new change
594610 rrs := * change .ResourceRecordSet
595- change2 := & route53.Change {Action : change .Action , ResourceRecordSet : & rrs }
611+ change2 := & Route53Change { Change : route53.Change {Action : change .Action , ResourceRecordSet : & rrs } }
596612 change2 .ResourceRecordSet .Type = aws .String (route53 .RRTypeAaaa )
597613 changes = append (changes , change2 )
598614 }
@@ -635,11 +651,13 @@ func (p *AWSProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoin
635651// returned Change is based on the given record by the given action, e.g.
636652// action=ChangeActionCreate returns a change for creation of the record and
637653// action=ChangeActionDelete returns a change for deletion of the record.
638- func (p * AWSProvider ) newChange (action string , ep * endpoint.Endpoint ) (* route53.Change , bool ) {
639- change := & route53.Change {
640- Action : aws .String (action ),
641- ResourceRecordSet : & route53.ResourceRecordSet {
642- Name : aws .String (ep .DNSName ),
654+ func (p * AWSProvider ) newChange (action string , ep * endpoint.Endpoint ) (* Route53Change , bool ) {
655+ change := & Route53Change {
656+ Change : route53.Change {
657+ Action : aws .String (action ),
658+ ResourceRecordSet : & route53.ResourceRecordSet {
659+ Name : aws .String (ep .DNSName ),
660+ },
643661 },
644662 }
645663 dualstack := false
@@ -736,15 +754,15 @@ func (p *AWSProvider) tagsForZone(ctx context.Context, zoneID string) (map[strin
736754 return tagMap , nil
737755}
738756
739- func batchChangeSet (cs [] * route53. Change , batchSize int ) [][] * route53. Change {
757+ func batchChangeSet (cs Route53Changes , batchSize int ) []Route53Changes {
740758 if len (cs ) <= batchSize {
741759 res := sortChangesByActionNameType (cs )
742- return [][] * route53. Change {res }
760+ return []Route53Changes {res }
743761 }
744762
745- batchChanges := make ([][] * route53. Change , 0 )
763+ batchChanges := make ([]Route53Changes , 0 )
746764
747- changesByName := make (map [string ][] * route53. Change )
765+ changesByName := make (map [string ]Route53Changes )
748766 for _ , v := range cs {
749767 changesByName [* v .ResourceRecordSet .Name ] = append (changesByName [* v .ResourceRecordSet .Name ], v )
750768 }
@@ -784,7 +802,7 @@ func batchChangeSet(cs []*route53.Change, batchSize int) [][]*route53.Change {
784802 return batchChanges
785803}
786804
787- func sortChangesByActionNameType (cs [] * route53. Change ) [] * route53. Change {
805+ func sortChangesByActionNameType (cs Route53Changes ) Route53Changes {
788806 sort .SliceStable (cs , func (i , j int ) bool {
789807 if * cs [i ].Action > * cs [j ].Action {
790808 return true
@@ -805,11 +823,11 @@ func sortChangesByActionNameType(cs []*route53.Change) []*route53.Change {
805823}
806824
807825// changesByZone separates a multi-zone change into a single change per zone.
808- func changesByZone (zones map [string ]* route53.HostedZone , changeSet [] * route53. Change ) map [string ][] * route53. Change {
809- changes := make (map [string ][] * route53. Change )
826+ func changesByZone (zones map [string ]* route53.HostedZone , changeSet Route53Changes ) map [string ]Route53Changes {
827+ changes := make (map [string ]Route53Changes )
810828
811829 for _ , z := range zones {
812- changes [aws .StringValue (z .Id )] = [] * route53. Change {}
830+ changes [aws .StringValue (z .Id )] = Route53Changes {}
813831 }
814832
815833 for _ , c := range changeSet {
@@ -828,9 +846,11 @@ func changesByZone(zones map[string]*route53.HostedZone, changeSet []*route53.Ch
828846 aliasTarget := * rrset .AliasTarget
829847 aliasTarget .HostedZoneId = aws .String (cleanZoneID (aws .StringValue (z .Id )))
830848 rrset .AliasTarget = & aliasTarget
831- c = & route53.Change {
832- Action : c .Action ,
833- ResourceRecordSet : & rrset ,
849+ c = & Route53Change {
850+ Change : route53.Change {
851+ Action : c .Action ,
852+ ResourceRecordSet : & rrset ,
853+ },
834854 }
835855 }
836856 changes [aws .StringValue (z .Id )] = append (changes [aws .StringValue (z .Id )], c )
0 commit comments