-
Notifications
You must be signed in to change notification settings - Fork 6
Route53 updater #945
Route53 updater #945
Changes from 19 commits
d7a9bd9
c4370b5
978bfb4
d1cbb82
ab63e2e
05fd65d
3686140
75936d4
4c87788
db0d282
dbfc530
620744b
a532930
983de50
4c1e72f
06482c2
d1c521e
e3d3ecf
3c18918
e7bb7e6
120cdf0
327a5c7
95153b0
b024196
a549551
0047289
56ff6aa
656252a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "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 { | ||
| panic(errors.New("Not enough arguments. Arguments must be non-empty strings passed into 'route53-updater <service-role> <internal-hosted-zone-name>'")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets use |
||
| } | ||
| serviceRole := os.Args[1] | ||
| internalHostedZoneName := os.Args[2] | ||
| if serviceRole == "" || internalHostedZoneName == "" { | ||
| panic(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() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
| panic(err) | ||
| } | ||
|
|
||
| awsClient := route53.New(session.New()) | ||
| hostedZones, err := awsClient.ListHostedZones(&route53.ListHostedZonesInput{}) | ||
| if err != nil { | ||
| panic(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 { | ||
| panic(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 { | ||
| panic(err) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,9 @@ resource "aws_iam_role_policy" "ecs_instance" { | |
| "ecr:GetDownloadUrlForLayer", | ||
| "ecr:BatchGetImage", | ||
| "ecs:StartTask", | ||
| "autoscaling:*" | ||
| "autoscaling:*", | ||
| "route53:ChangeResourceRecordSets", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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": "*" | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about checking
if len(os.Args) != 3?