This repository was archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Route53 updater #945
Merged
Merged
Route53 updater #945
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d7a9bd9
address comments
c4370b5
test
978bfb4
update
d1cbb82
update
ab63e2e
update
05fd65d
update
3686140
update
75936d4
update
4c87788
update
db0d282
update
dbfc530
update
620744b
update
a532930
update
983de50
update
4c1e72f
Merge branch 'hh-worker-ports' into hh-worker-ports-remote
06482c2
update
d1c521e
Merge branch 'hh-worker-ports' into hh-worker-ports-remote
e3d3ecf
update
3c18918
update
e7bb7e6
address comments
120cdf0
service endpoints
327a5c7
http call
95153b0
resolve merge conflicts
b024196
restrict policy to internal zones
a549551
move policy
0047289
update
56ff6aa
update
656252a
change resource
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| 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) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": "*" | ||
| }, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does it make sense to run this as an external command or just make an http request here?