Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

builtin/aws/ecs: Fix DNS Record creation #1256

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .changelog/1256.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
plugin/aws/ecs: Route 53 "A" Type record properly created when not found for domain name
```
23 changes: 16 additions & 7 deletions builtin/aws/ecs/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ func createALB(
records, err := r53.ListResourceRecordSets(&route53.ListResourceRecordSetsInput{
HostedZoneId: aws.String(albConfig.ZoneId),
StartRecordName: aws.String(albConfig.FQDN),
StartRecordType: aws.String("A"),
StartRecordType: aws.String(route53.RRTypeA),
MaxItems: aws.String("1"),
})
if err != nil {
Expand All @@ -776,14 +776,23 @@ func createALB(

fqdn := albConfig.FQDN

// Add trailing period to match Route53 record name
if fqdn[len(fqdn)-1] != '.' {
fqdn += "."
}

if len(records.ResourceRecordSets) > 0 && *(records.ResourceRecordSets[0].Name) == fqdn {
s.Status("Found existing Route53 record: %s", *records.ResourceRecordSets[0].Name)
L.Debug("found existing record, assuming it's correct")
} else {
var recordExists bool

if len(records.ResourceRecordSets) > 0 {
record := records.ResourceRecordSets[0]
if aws.StringValue(record.Type) == route53.RRTypeA && aws.StringValue(record.Name) == fqdn {
s.Status("Found existing Route53 record: %s", aws.StringValue(record.Name))
L.Debug("found existing record, assuming it's correct")
recordExists = true
}
}

if !recordExists {
s.Status("Creating new Route53 record: %s (zone-id: %s)",
albConfig.FQDN, albConfig.ZoneId)

Expand All @@ -792,10 +801,10 @@ func createALB(
ChangeBatch: &route53.ChangeBatch{
Changes: []*route53.Change{
{
Action: aws.String("CREATE"),
Action: aws.String(route53.ChangeActionCreate),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(albConfig.FQDN),
Type: aws.String("A"),
Type: aws.String(route53.RRTypeA),
AliasTarget: &route53.AliasTarget{
DNSName: lb.DNSName,
EvaluateTargetHealth: aws.Bool(true),
Expand Down