Skip to content

Commit

Permalink
Merge pull request #668 from artichoke/dev/lopopolo-dns-zone-project
Browse files Browse the repository at this point in the history
Migrate route53 zone setup to a project
  • Loading branch information
lopopolo authored Nov 22, 2024
2 parents ba5471e + 57bb251 commit fd94c30
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
variable "phase" {
description = "Provisioning phase, either `per-host`, `per-cluster` or `global`"
description = "Provisioning phase, either `per-host`, `per-cluster`, `per-domain`, or `global`"
type = string

validation {
condition = var.phase == "per-host" || var.phase == "per-cluster" || var.phase == "global"
error_message = "The phase variable must be either 'per-host', 'per-cluster', or 'global'."
condition = var.phase == "per-host" || var.phase == "per-cluster" || var.phase == "per-domain" || var.phase == "global"
error_message = "The phase variable must be either 'per-host', 'per-cluster', 'per-domain', or 'global'."
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
variable "phase" {
description = "Provisioning phase, either `per-host`, `per-cluster` or `global`"
description = "Provisioning phase, either `per-host`, `per-cluster`, `per-domain`, or `global`"
type = string

validation {
condition = var.phase == "per-host" || var.phase == "per-cluster" || var.phase == "global"
error_message = "The phase variable must be either 'per-host', 'per-cluster', or 'global'."
condition = var.phase == "per-host" || var.phase == "per-cluster" || var.phase == "per-domain" || var.phase == "global"
error_message = "The phase variable must be either 'per-host', 'per-cluster', 'per-domain', or 'global'."
}
}

Expand Down
6 changes: 3 additions & 3 deletions terraform/projects/remote-state/modules/global/variables.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
variable "phase" {
description = "Provisioning phase, either `per-host`, `per-cluster` or `global`"
description = "Provisioning phase, either `per-host`, `per-cluster`, `per-domain`, or `global`"
type = string

validation {
condition = var.phase == "per-host" || var.phase == "per-cluster" || var.phase == "global"
error_message = "The phase variable must be either 'per-host', 'per-cluster', or 'global'."
condition = var.phase == "per-host" || var.phase == "per-cluster" || var.phase == "per-domain" || var.phase == "global"
error_message = "The phase variable must be either 'per-host', 'per-cluster', 'per-domain', or 'global'."
}
}

Expand Down
25 changes: 25 additions & 0 deletions terraform/projects/route53-dns/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions terraform/projects/route53-dns/aws.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
provider "aws" {
region = var.region

default_tags {
tags = {
managed_by = "terraform"
plan = var.plan
}
}
}

provider "aws" {
alias = "us_east_1"
region = "us-east-1"

default_tags {
tags = {
managed_by = "terraform"
plan = var.plan
}
}
}
3 changes: 3 additions & 0 deletions terraform/projects/route53-dns/domain-data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "domain_data" {
source = "../../modules/domain-data"
}
9 changes: 9 additions & 0 deletions terraform/projects/route53-dns/domains.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "route53_dns_domain" {
for_each = toset(module.domain_data.domains)
source = "./modules/per-domain"

plan = var.plan
region = var.region
phase = "per-domain"
domain_name = each.value
}
9 changes: 9 additions & 0 deletions terraform/projects/route53-dns/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
backend "s3" {
bucket = "artichoke-forge-project-infrastructure-terraform-state"
region = "us-west-2"
key = "route53-dns/terraform.tfstate"
encrypt = true
dynamodb_table = "terraform_statelock"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "domain_data" {
source = "../../../../modules/domain-data"
}
7 changes: 7 additions & 0 deletions terraform/projects/route53-dns/modules/per-domain/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aws_route53_zone" "zone" {
name = var.domain_name

lifecycle {
prevent_destroy = true
}
}
15 changes: 15 additions & 0 deletions terraform/projects/route53-dns/modules/per-domain/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output "zone_name" {
value = aws_route53_zone.zone.name
}

output "zone_id" {
value = aws_route53_zone.zone.zone_id
}

output "zone_arn" {
value = aws_route53_zone.zone.arn
}

output "zone_name_servers" {
value = [for ns in aws_route53_zone.zone.name_servers : ns]
}
34 changes: 34 additions & 0 deletions terraform/projects/route53-dns/modules/per-domain/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
variable "domain_name" {
description = "Domain name"
type = string
}

variable "phase" {
description = "Provisioning phase, either `per-host`, `per-cluster`, `per-domain`, or `global`"
type = string

validation {
condition = var.phase == "per-host" || var.phase == "per-cluster" || var.phase == "per-domain" || var.phase == "global"
error_message = "The phase variable must be either 'per-host', 'per-cluster', 'per-domain', or 'global'."
}
}

variable "plan" {
description = "Plan name"
type = string

validation {
condition = length(var.plan) >= 3 && !can(regex("artichoke", var.plan))
error_message = "The plan variable must be at least 3 characters long and must not contain the string 'artichoke'."
}
}

variable "region" {
description = "AWS region"
type = string

validation {
condition = contains(["us-west-2", "us-west-1", "us-east-1", "us-east-2"], var.region)
error_message = "The region must be one of the following: us-west-2 (Oregon), us-west-1 (California), us-east-1, or us-east-2."
}
}
7 changes: 7 additions & 0 deletions terraform/projects/route53-dns/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "route53_dns_domains" {
description = "Route53 zone information for each domain"
value = {
for domain_name in module.domain_data.domains :
domain_name => module.route53_dns_domain[domain_name]
}
}
11 changes: 11 additions & 0 deletions terraform/projects/route53-dns/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "plan" {
description = "Plan name"
default = "route53-dns"
type = string
}

variable "region" {
description = "AWS region"
default = "us-west-2"
type = string
}
10 changes: 10 additions & 0 deletions terraform/projects/route53-dns/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.10"
}
}

required_version = "~> 1.0"
}

0 comments on commit fd94c30

Please sign in to comment.