Creating a Route 53 Hosted Zone
Overview
This short guide will run through the process of creating a Route 53 Hosted Zone through Terraform for your environment.
Pre-Requisites
This guide assumes you have an environment already created in the Live
cluster and defined in the cloud-platform-environments repository.
Terraform files
Copy the Terraform resource code below and save it into the respective 3 files in the [your namespace]/resources
directory in the cloud-platform-environments repository:
main.tf
route53.tf
variables.tf
main.tf
terraform {
backend "s3" {}
}
provider "aws" {
region = "eu-west-2"
}
Note: If you already have that file defined in your environment, do not recreate it.
variable.tf
This file declares the variables fields utilisised in the route53.tf file below
Fill in the variable namespace field below with your existing kubernetes namespace.
variable "namespace" {
default = "YOUR KUBERNETES NAMESPACE GOES HERE"
}
variable "business-unit" {
default = "example-bu"
}
variable "team_name" {
default = "example-team-name"
}
variable "application" {
default = "example-app"
}
variable "environment-name" {
default = "dev"
}
variable "is-production" {
default = "false"
}
variable "infrastructure-support" {
default = "example@example.com"
}
variable "owner" {
default = "example-owner"
}
Note: If you already have that file defined in your environment, do not recreate it
route53.tf
Fill in the name field below with your domain name.
resource "aws_route53_zone" "example_team_route53_zone" {
name = "YOUR DOMAIN GOES HERE"
tags = {
team_name = var.team_name
business-unit = var.business-unit
application = var.application
is-production = var.is-production
environment-name = var.environment-name
owner = var.owner
infrastructure-support = var.infrastructure-support
namespace = var.namespace
}
}
resource "kubernetes_secret" "example_route53_zone_sec" {
metadata {
name = "example-route53-zone-output"
namespace = var.namespace
}
data = {
zone_id = aws_route53_zone.example_team_route53_zone.zone_id
}
}
Creating the resource
Make sure to replace the placeholders and example values above with relevant ones. If you are referring from variables in variables.tf, replace with var.VARIABLE NAME
. Commit your changes to a branch and raise a pull request.
Once approved, you can merge and the changes will be applied.
Shortly after, to confirm the zone has been created, you should be able to access the Zone_ID
as Secret on kubernetes in your namespace.
Support ticket
Please raise a support ticket with the Cloud Platform.
Provide them with the domain name, the Cloud Platform team will finalize the process by creating a matching NS record in the DSD account.
Add DNS records to a route53 zone
You can add DNS records for the zone you created, using the aws_route53_record terraform resource.
Example below, will add a record set of type “CNAME” to the route53 zone.
resource "aws_route53_record" "add_cname_email" {
name = "YOUR DOMAIN GOES HERE"
zone_id = aws_route53_zone.example_team_route53_zone.zone_id
type = "CNAME"
records = ["test.org"]
ttl = "300"
}
Follow the example-usage, to create different type of record sets, using aws_route53_record resource.