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

Commit

Permalink
Merge pull request #1256 from anGie44/b-ecs-plugin-record-sets
Browse files Browse the repository at this point in the history
builtin/aws/ecs: Fix DNS Record creation
  • Loading branch information
evanphx authored Apr 9, 2021
2 parents 356f3b6 + 5d9c091 commit 7376b07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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

0 comments on commit 7376b07

Please sign in to comment.