|
| 1 | +# Domain names and DNS |
| 2 | + |
| 3 | +All the DNS records of the domains owned by the Rust Infrastructure team are |
| 4 | +hosted on [AWS Route 53], and can be tweaked by members of the team. This |
| 5 | +document contains instructions for them on how to make changes. |
| 6 | + |
| 7 | +## Changing DNS records of a domain managed with Terraform |
| 8 | + |
| 9 | +> **Warning:** not all domain names are yet managed with Terraform. In the |
| 10 | +> [console][hosted-zones], if a zone's comment doesn't start with `[terraform]` |
| 11 | +> you'll need to make changes manually from the UI. Work is underway to migrate |
| 12 | +> every domain to Terraform though. |
| 13 | +
|
| 14 | +> **Warning:** [`terraform/services/dns`][dns-dir] only contains the definition |
| 15 | +> of domain names pointing to resources managed outside of Terraform. When |
| 16 | +> Terraform manages a resource it will automatically add the required records |
| 17 | +> on its own. See the service's documentation to learn where its Terraform |
| 18 | +> configuration lives. |
| 19 | +
|
| 20 | +DNS records are managed in the [`terraform/services/dns`][dns-dir] directory of |
| 21 | +our Terraform configuration. A file named after the domain name, ending in |
| 22 | +`.tf`, exists for each managed domain, and it contains some basic information |
| 23 | +plus its records. |
| 24 | + |
| 25 | +The configuration supports adding A, CNAME, MX and TXT records. Inside the |
| 26 | +module definition contained in the domain's file, each record type has its own |
| 27 | +map: the map keys are the names of the records, while the values are a list of |
| 28 | +record values. |
| 29 | + |
| 30 | +For example, to add a `pages.rust-lang.org` CNAME pointing to |
| 31 | +`rust-lang.github.io` you'll need to add this to |
| 32 | +`terraform/services/dns/rust-lang.org`: |
| 33 | + |
| 34 | +```terraform |
| 35 | +module "rust_lang_org" { |
| 36 | + # ... |
| 37 | +
|
| 38 | + CNAME = { |
| 39 | + "pages.rust-lang.org." = ["rust-lang.github.io"], |
| 40 | + # ... |
| 41 | + } |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Once you made all the changes you can apply them with: |
| 46 | + |
| 47 | +``` |
| 48 | +terraform apply |
| 49 | +``` |
| 50 | + |
| 51 | +## Managing DNS for a new domain with Terraform |
| 52 | + |
| 53 | +Setting up Terraform to manage the DNS records of a new domain name involves a |
| 54 | +few steps. First of all you need to decide the identifier used inside |
| 55 | +Terraform for that domain. By convention, the identifier is the domain name |
| 56 | +itself with `.` and `-` replaced with `_`. For example `rust-lang.org` becomes |
| 57 | +`rust_lang_org`. |
| 58 | + |
| 59 | +Then you can create a file in [`terraform/services/dns`][dns-dir] named after |
| 60 | +the domain name, ending in `.tf`, with this content (take care of replacing the |
| 61 | +placeholders): |
| 62 | + |
| 63 | +```terraform |
| 64 | +module "<IDENTIFIER>" { |
| 65 | + source = "./domain" |
| 66 | +
|
| 67 | + domain = "<DOMAIN-NAME>" |
| 68 | + comment = "<COMMENT-FOR-THE-DOMAIN>" |
| 69 | + ttl = 300 |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +Finally you need to output the ID of the Route53 zone, allowing other parts of |
| 74 | +our Terraform configuration to add records. Add this snippet to |
| 75 | +[`terraform/services/dns/outputs.tf`][outputs-file]: |
| 76 | + |
| 77 | +```terraform |
| 78 | +# ... |
| 79 | +
|
| 80 | +output "zone_<IDENTIFIER>" { |
| 81 | + value = module.<IDENTIFIER>.zone_id |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +Once you're done you can apply the changes with: |
| 86 | + |
| 87 | +``` |
| 88 | +terraform init |
| 89 | +terraform apply |
| 90 | +``` |
| 91 | + |
| 92 | +[AWS Route 53]: https://aws.amazon.com/route53/ |
| 93 | +[hosted-zones]: https://console.aws.amazon.com/route53/home#hosted-zones: |
| 94 | +[dns-dir]: https://github.com/rust-lang/simpleinfra/tree/master/terraform/services/dns/ |
| 95 | +[outputs-file]: https://github.com/rust-lang/simpleinfra/blob/master/terraform/services/dns/outputs.tf |
0 commit comments