This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from kinvolk/johananl/packet-cloudflare-dns
Packet: Add Cloudflare DNS support
- Loading branch information
Showing
26 changed files
with
588 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
data "cloudflare_zones" "selected" { | ||
filter { | ||
name = var.dns_zone | ||
status = "active" | ||
paused = false | ||
} | ||
} | ||
|
||
resource "cloudflare_record" "apiserver_public" { | ||
count = length(var.controllers_public_ipv4) | ||
|
||
zone_id = lookup(data.cloudflare_zones.selected.zones[0], "id") | ||
name = format("%s.%s.", var.cluster_name, var.dns_zone) | ||
type = "A" | ||
ttl = 300 | ||
value = var.controllers_public_ipv4[count.index] | ||
} | ||
|
||
resource "cloudflare_record" "apiserver_private" { | ||
count = length(var.controllers_private_ipv4) | ||
|
||
zone_id = lookup(data.cloudflare_zones.selected.zones[0], "id") | ||
name = format("%s-private.%s.", var.cluster_name, var.dns_zone) | ||
type = "A" | ||
ttl = 300 | ||
value = var.controllers_private_ipv4[count.index] | ||
} | ||
|
||
resource "cloudflare_record" "etcd" { | ||
count = length(var.controllers_private_ipv4) | ||
|
||
zone_id = lookup(data.cloudflare_zones.selected.zones[0], "id") | ||
name = format("%s-etcd%d.%s.", var.cluster_name, count.index, var.dns_zone) | ||
type = "A" | ||
ttl = 300 | ||
value = var.controllers_private_ipv4[count.index] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
terraform { | ||
required_version = ">= 0.12.0" | ||
|
||
required_providers { | ||
cloudflare = "~> 2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../shared-variables.tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
locals { | ||
api_external_fqdn = format("%s.%s.", var.cluster_name, var.dns_zone) | ||
api_fqdn = format("%s-private.%s.", var.cluster_name, var.dns_zone) | ||
etcd_fqdn = [for i, d in var.controllers_private_ipv4 : format("%s-etcd%d.%s.", var.cluster_name, i, var.dns_zone)] | ||
|
||
dns_entries = concat( | ||
[ | ||
# apiserver public | ||
{ | ||
name = local.api_external_fqdn, | ||
type = "A", | ||
ttl = 300, | ||
records = var.controllers_public_ipv4 | ||
}, | ||
# apiserver private | ||
{ | ||
name = local.api_fqdn, | ||
type = "A", | ||
ttl = 300, | ||
records = var.controllers_private_ipv4 | ||
}, | ||
], | ||
# etcd | ||
[ | ||
for index, i in var.controllers_private_ipv4 : | ||
{ | ||
name = local.etcd_fqdn[index], | ||
type = "A", | ||
ttl = 300, | ||
records = [i], | ||
} | ||
], | ||
) | ||
} | ||
|
||
output "entries" { | ||
value = local.dns_entries | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform { | ||
required_version = ">= 0.12.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../shared-variables.tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
variable "entries" { | ||
type = list( | ||
object({ | ||
name = string | ||
type = string | ||
ttl = number | ||
records = list(string) | ||
}) | ||
) | ||
provider "aws" { | ||
# The Route 53 service doesn't need a specific region to operate, however | ||
# the AWS Terraform provider needs it and the documentation suggests to use | ||
# "us-east-1": https://docs.aws.amazon.com/general/latest/gr/r53.html. | ||
region = "us-east-1" | ||
} | ||
|
||
variable "aws_zone_id" { | ||
type = string | ||
description = "AWS Route53 DNS Zone ID (e.g. Z3PAABBCFAKEC0)" | ||
data "aws_route53_zone" "selected" { | ||
name = "${var.dns_zone}." | ||
} | ||
|
||
resource "aws_route53_record" "dns-records" { | ||
count = length(var.entries) | ||
resource "aws_route53_record" "apiserver_public" { | ||
zone_id = data.aws_route53_zone.selected.zone_id | ||
name = format("%s.%s.", var.cluster_name, var.dns_zone) | ||
type = "A" | ||
ttl = 300 | ||
records = var.controllers_public_ipv4 | ||
} | ||
|
||
resource "aws_route53_record" "apiserver_private" { | ||
zone_id = data.aws_route53_zone.selected.zone_id | ||
name = format("%s-private.%s.", var.cluster_name, var.dns_zone) | ||
type = "A" | ||
ttl = 300 | ||
records = var.controllers_private_ipv4 | ||
} | ||
|
||
# Route53 DNS Zone where record should be created | ||
zone_id = var.aws_zone_id | ||
resource "aws_route53_record" "etcd" { | ||
count = length(var.controllers_private_ipv4) | ||
|
||
name = var.entries[count.index].name | ||
type = var.entries[count.index].type | ||
ttl = var.entries[count.index].ttl | ||
records = var.entries[count.index].records | ||
zone_id = data.aws_route53_zone.selected.zone_id | ||
name = format("%s-etcd%d.%s.", var.cluster_name, count.index, var.dns_zone) | ||
type = "A" | ||
ttl = 300 | ||
records = [var.controllers_private_ipv4[count.index]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# Terraform version and plugin versions | ||
|
||
terraform { | ||
required_version = ">= 0.12.0" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../shared-variables.tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This file contains variables which are shared among all modules in this directory. Its purpose is | ||
# to reduce duplication and assist in enforcing a common "interface" for all the modules. | ||
|
||
variable "cluster_name" { | ||
type = string | ||
description = "Unique cluster name (prepended to dns_zone)" | ||
} | ||
|
||
variable "controllers_public_ipv4" { | ||
type = list(string) | ||
description = "Public IPv4 addresses of all the controllers in the cluster" | ||
} | ||
|
||
variable "controllers_private_ipv4" { | ||
type = list(string) | ||
description = "Private IPv4 addresses of all the controllers in the cluster" | ||
} | ||
|
||
variable "dns_zone" { | ||
type = string | ||
description = "Zone name under which records should be created (e.g. example.com)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.