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 49
Packet: Add Cloudflare DNS support #422
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2d312b3
packet: Refactor DNS handling
johananl f3a4bc9
packet: Add Cloudflare DNS support
johananl 6f76077
docs: Update DNS knobs in Packet config reference
johananl 762b920
docs/concepts: Add a document about DNS
johananl 8651b10
docs: Remove extra space
johananl 7ca5607
docs/how-to-guides: Add a guide for Cloudflare DNS
johananl ad43144
ci/packet: Update DNS config
johananl 27841e7
dns: Use symlinks to reduce TF var duplication
johananl e233f6d
dns: Rename Ttl to TTL
johananl 8c5b515
packet: Wait for cloud DNS records
johananl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I don't think modules should be instantiating the providers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module didn't run for me without this since the AWS provider requires a region and I need to instantiate the provider to specify the region AFAIK. Do you have an alternative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instantiating code should also instantiate the provider as far as I know. So this block should be conditionally added together with module instantiation in Packet's Terraform template I guess. Something like:
I'm not sure how big deal that is though. Perhaps we will find out, when porting those changes to AWS for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@invidian +1. The module should use the providers meta-argument if a custom one is needed. If not, it seems cleaner and according to terraform best practices to define it in the top level terraform file.
Should we create an issue to track this? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #539.