Skip to content

Commit

Permalink
Group By Endpoint names per Hosted Zone on AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocaylent committed Mar 3, 2024
1 parent 6cf4783 commit b8053fe
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ func sortChangesByActionNameType(cs Route53Changes) Route53Changes {
// changesByZone separates a multi-zone change into a single change per zone.
func changesByZone(zones map[string]*route53.HostedZone, changeSet Route53Changes) map[string]Route53Changes {
changes := make(map[string]Route53Changes)
visitedHostnames := make(map[string]map[string]bool)

for _, z := range zones {
changes[aws.StringValue(z.Id)] = Route53Changes{}
Expand All @@ -993,6 +994,15 @@ func changesByZone(zones map[string]*route53.HostedZone, changeSet Route53Change
continue
}
for _, z := range zones {
// Initialize the map for the current zone if it doesn't exist
if visitedHostnames[aws.StringValue(z.Id)] == nil {
visitedHostnames[aws.StringValue(z.Id)] = make(map[string]bool)
}

if visitedHostnames[aws.StringValue(z.Id)][hostname] {
log.Debugf("Skipping duplicate %s to zone %s [Id: %s]", hostname, aws.StringValue(z.Name), aws.StringValue(z.Id))
continue
}
if c.ResourceRecordSet.AliasTarget != nil && aws.StringValue(c.ResourceRecordSet.AliasTarget.HostedZoneId) == sameZoneAlias {
// alias record is to be created; target needs to be in the same zone as endpoint
// if it's not, this will fail
Expand All @@ -1008,6 +1018,7 @@ func changesByZone(zones map[string]*route53.HostedZone, changeSet Route53Change
}
}
changes[aws.StringValue(z.Id)] = append(changes[aws.StringValue(z.Id)], c)
visitedHostnames[aws.StringValue(z.Id)][hostname] = true
log.Debugf("Adding %s to zone %s [Id: %s]", hostname, aws.StringValue(z.Name), aws.StringValue(z.Id))
}
}
Expand Down

0 comments on commit b8053fe

Please sign in to comment.