StackExchange / dnscontrol

Infrastructure as code for DNS!
https://dnscontrol.org/
MIT License
3.07k stars 389 forks source link

Route53 Traffic policy record #585

Open perrfect opened 4 years ago

perrfect commented 4 years ago

Hi. On Route53 i have Traffic policy for geolocation for a domain. Can i manage this type of record through dnscontrol?

tlimoncelli commented 4 years ago

Hi!

DNSControl doesn't currently manage that. We'd be open to PRs that add that feature.

I believe that Terraform supports that kind of thing.

perrfect commented 4 years ago

Thank you

truthdoug commented 2 years ago

@perrfect Did you find a solution for this?

perrfect commented 2 years ago

@perrfect Did you find a solution for this?

Hello. No, i didn't find the solution(

truthdoug commented 1 year ago

Adding some notes here because I got curious about this again.

For this example, traffic from the EU goes to a cloudfront distribution and other traffic goes to an S3 bucket.

Using the aws command line, I grabbed all json data for my zone like this: aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/redacted

The geolocated records look like this:

{
    "ResourceRecordSets": [
        {
            "Name": "example.org.",
            "Type": "A",
            "SetIdentifier": "default-configuration-geolocation",
            "GeoLocation": {
                "CountryCode": "*"
            },
            "AliasTarget": {
                "HostedZoneId": "redacted1",
                "DNSName": "s3-example-us-east-1.amazonaws.com.",
                "EvaluateTargetHealth": false
            }
        },
        {
            "Name": "example.org.",
            "Type": "A",
            "SetIdentifier": "europe-record",
            "GeoLocation": {
                "ContinentCode": "EU"
            },
            "AliasTarget": {
                "HostedZoneId": "redacted2",
                "DNSName": "example.cloudfront.net.",
                "EvaluateTargetHealth": false
            }
        }
    ]
}

Using dnscontrol get-zones -format=js, the resulting lines currently look like this:

R53_ALIAS('@', 'A', 's3-example-us-east-1.amazonaws.com.', R53_ZONE('redacted1')),
R53_ALIAS('@', 'A', 'example.cloudfront.net.', R53_ZONE('redacted2')),

From a UX point of view, my first thought was that the geolocation could be added as an argument to R53_ALIAS() but that won't work because other types of records (A, CNAME, etc) can also have geolocation variants.

I've looked a bit at providers/route53/route53Provider.go but I'm not sure where to start with this.

Is there a similar provider-specific feature that might be a good model for implementing this?

tlimoncelli commented 1 year ago

Ah! That json is very enlightening!

My recommendation is to add something like: R53_GEOZONE() that would accept a dictionary with all the various parameters. That would be stored in the metadata for that record for use by the provider.

R53_ALIAS('@', 'A', 's3-example-us-east-1.amazonaws.com.', R53_ZONE('redacted1'),
          R53_GEO( {
            "SetIdentifier": "default-configuration-geolocation",
            "GeoLocation": {
                "CountryCode": "*"
            },
            "AliasTarget": {
                "HostedZoneId": "redacted1",
                "DNSName": "s3-example-us-east-1.amazonaws.com.",
                "EvaluateTargetHealth": false
            }
       }),
R53_ALIAS('@', 'A', 'example.cloudfront.net.', R53_ZONE('redacted2'),
       R53_GEO( {
            "SetIdentifier": "europe-record",
            "GeoLocation": {
                "ContinentCode": "EU"
            },
            "AliasTarget": {
                "HostedZoneId": "redacted2",
                "DNSName": "example.cloudfront.net.",
                "EvaluateTargetHealth": false
            }
       }),

It isn't pretty, but ... we could add a R53_GEO_BUILDER() function later.

I lack time to write this kind of feature (Stack isn't giving me time to work on features that Stack doesn't use). However I'd be glad to walk you through it. It would be relatively straight forward. The integration tests take out a lot of the guess-work.

truthdoug commented 1 year ago

I'm intrigued by the idea of writing support for this with your guidance, @tlimoncelli

... in the interim, I just read about the new IGNORE feature. Am I correct in thinking that this might be a good stop gap solution? By using IGNORE() on the records that have the Route53 geolocation designation, I could then manage the other records on this zone using dnscontrol.

Does that sound right?

tlimoncelli commented 1 year ago

Yes! That should work! Try putting an IGNORE() in that matches any records you create manually (i.e. clickops)