Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 20 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
1 change: 1 addition & 0 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ set -e

bin/build_bin_data
go install github.com/Originate/exosphere/src/cmd/exo
go install github.com/Originate/exosphere/resources/update-route53
5 changes: 5 additions & 0 deletions bin/cross-compile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ gox -ldflags "-X github.com/Originate/exosphere/cmd.Version=$TRAVIS_TAG -X githu
-osarch "darwin/386 darwin/amd64 linux/386 linux/amd64 linux/arm windows/386 windows/amd64" \
-output "dist/exo-{{.OS}}-{{.Arch}}" \
github.com/Originate/exosphere/src/cmd/exo

gox -ldflags "-X github.com/Originate/exosphere/cmd.Version=$TRAVIS_TAG -X github.com/Originate/exosphere/cmd.BuildTime=$timestamp) -X github.com/Originate/exosphere/cmd.GitHash=$sha" \
-osarch "linux/386 linux/amd64 linux/arm" \
-output "dist/update-route53-{{.OS}}-{{.Arch}}" \
github.com/Originate/exosphere/resources/update-route53
68 changes: 68 additions & 0 deletions resources/update-route53/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"errors"
"fmt"
"log"
"os"
"os/exec"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
)

func main() {
if len(os.Args) != 3 {
log.Fatalln(errors.New("Wrong number of arguments. Arguments must be non-empty strings passed into 'route53-updater <service-role> <internal-hosted-zone-name>'"))
}
serviceRole := os.Args[1]
internalHostedZoneName := os.Args[2]
if serviceRole == "" || internalHostedZoneName == "" {
log.Fatalln(errors.New("Service role or internal hosted zone name missing. Both arguments must be non-empty strings passed into 'route53-updater <service-role> <internal-hosted-zone-name>'"))
}
internalIP, err := exec.Command("curl", "-fsSL", "http://169.254.169.254/latest/meta-data/local-ipv4").Output()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to run this as an external command or just make an http request here?

if err != nil {
log.Fatalln(err)
}

awsClient := route53.New(session.New())
hostedZones, err := awsClient.ListHostedZones(&route53.ListHostedZonesInput{})
if err != nil {
log.Fatalln(err)
}
var hostedZoneId *string
var hostedZoneFound bool
for _, hostedZone := range hostedZones.HostedZones {
if *hostedZone.Name == fmt.Sprintf("%s.", internalHostedZoneName) {
hostedZoneId = hostedZone.Id
hostedZoneFound = true
}
}
if !hostedZoneFound {
log.Fatalln(fmt.Errorf("Hosted zone name '%s' not found.", internalHostedZoneName))
}

_, err = awsClient.ChangeResourceRecordSets(&route53.ChangeResourceRecordSetsInput{
HostedZoneId: hostedZoneId,
ChangeBatch: &route53.ChangeBatch{
Comment: aws.String("Update dns record"),
Changes: []*route53.Change{
{
Action: aws.String("UPSERT"),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(fmt.Sprintf("%s.%s", serviceRole, internalHostedZoneName)),
Type: aws.String("A"),
TTL: aws.Int64(int64(300)),
ResourceRecords: []*route53.ResourceRecord{
{Value: aws.String(string(internalIP))},
},
},
},
},
},
})
if err != nil {
log.Fatalln(err)
}
}
4 changes: 3 additions & 1 deletion terraform/aws/ecs-cluster/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ resource "aws_iam_role_policy" "ecs_instance" {
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecs:StartTask",
"autoscaling:*"
"autoscaling:*",
"route53:ChangeResourceRecordSets",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should restrict this to only allow changes on the internal hosted zone

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would we restrict it to only the internal hosted zone in aim roles?

"route53:ListHostedZones"
],
"Resource": "*"
},
Expand Down