Skip to content

Commit 6654452

Browse files
author
Pierre Ugaz
committed
chore: init repo
0 parents  commit 6654452

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# k8s Route53 subzone
2+
3+
Create a subzone for a kubernetes cluster from an existing hosted zone in Route53
4+
5+
```hcl
6+
module "subzone" {
7+
source = "./"
8+
main_domain = var.main_domain
9+
zone_domain = var.resource_name
10+
}
11+
```
12+
13+
|Variable|Description|Required|Value|
14+
|---|---|---|---|
15+
|`main_domain`|Domain to create the subzone from|X||
16+
|`main_private`|Wether the main domain is private or not||`false`|
17+
|`zone_prefixes`|Prefixes list for hosted zones to be created (e.g. `["dev", "qa"]`)|X||
18+
|`zone_force_destroy`|Wether the subzone should force-destroyed upon destruction removing all records or not||`true`|
19+
|`zone_record_ttl`|TTL for subzone NS record||`"30"`|

local.tf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
locals {
2+
api_server_records = compact(var.api_server_lb)
3+
hosted_zone = format("%s.%s", var.zone_prefix, var.main_domain)
4+
records = [aws_route53_record.record, aws_route53_record.zone, aws_route53_zone.zone]
5+
zone_records = list(local.hosted_zone, format("dex.%s", local.hosted_zone))
6+
}

main.tf

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
data aws_route53_zone main {
2+
name = var.main_domain
3+
private_zone = var.main_private
4+
}
5+
6+
resource aws_route53_zone zone {
7+
force_destroy = var.zone_force_destroy
8+
name = local.hosted_zone
9+
}
10+
11+
resource aws_route53_record zone {
12+
name = local.hosted_zone
13+
records = aws_route53_zone.zone.name_servers
14+
ttl = var.record_ttl
15+
type = "NS"
16+
zone_id = data.aws_route53_zone.main.zone_id
17+
}
18+
19+
resource aws_route53_record record {
20+
count = length(local.zone_records)
21+
name = element(local.zone_records, count.index)
22+
records = local.api_server_records
23+
ttl = var.record_ttl
24+
type = "A"
25+
zone_id = aws_route53_zone.zone.zone_id
26+
}

output.tf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
output api_server_fqdn { value = aws_route53_record.record.0.fqdn }
2+
output dex_fqdn { value = aws_route53_record.record.1.fqdn }
3+
output name_servers { value = aws_route53_zone.zone.name_servers }
4+
output record { value = local.records }
5+
output zone_id { value = aws_route53_zone.zone.zone_id }
6+
output zone_record_name { value = aws_route53_record.zone.name }

vars.tf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
variable api_server_lb { default = [] }
2+
variable main_domain { type = string }
3+
variable main_private { default = false }
4+
variable record_ttl { default = "30" }
5+
variable zone_force_destroy { default = true }
6+
variable zone_prefix { type = string }

versions.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
}
6+
}
7+
required_version = ">= 0.13"
8+
}

0 commit comments

Comments
 (0)