Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only select public zones #19

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,31 @@ func (p *Provider) getZoneID(ctx context.Context, zoneName string) (string, erro
}
}

matchingZones := []types.HostedZone{}

if len(getZoneResult.HostedZones) > 0 {
if *getZoneResult.HostedZones[0].Name == zoneName {
return *getZoneResult.HostedZones[0].Id, nil
for z := 0; z < len(getZoneResult.HostedZones); z++ {
if *getZoneResult.HostedZones[z].Name == zoneName {
matchingZones = append(matchingZones, getZoneResult.HostedZones[z])
}
}
}

if len(matchingZones) == 1 {
return *matchingZones[0].Id, nil
}

// If multiple zones matched the name
if len(matchingZones) > 1 {
// Select the first public (i.e. ot-private) zone as a best guess.
for m := 0; m < len(matchingZones); m++ {
if !matchingZones[m].Config.PrivateZone {
return *matchingZones[m].Id, nil
}
}
// All zone were private, give up and return.
// Historically we always returned the first match without checking for public/private
return *matchingZones[0].Id, nil
}

return "", fmt.Errorf("HostedZoneNotFound: No zones found for the domain %s", zoneName)
Expand Down