Skip to content

Commit

Permalink
Add cloudlfare dns management
Browse files Browse the repository at this point in the history
  • Loading branch information
vcscsvcscs committed Mar 10, 2024
1 parent b82d213 commit 65ab50b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ terraform.rc
*.terraform.lock.hcl
oci-managed/oke/kubeconfig
oci-managed/traefik-values.yml
cert.pem
cert.key
oci-managed/nlb/traefik_values.yaml
40 changes: 40 additions & 0 deletions oci-managed/nlb/dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
data "oci_network_load_balancer_network_load_balancers" "traefik" {
compartment_id = var.compartment_ocid
state = "Active"
depends_on = [helm_release.traefik]
}

locals {
traefik_nlb_public_ip = data.oci_network_load_balancer_network_load_balancers.traefik.network_load_balancer_collection[0].items[0].ip_addresses[0].ip_address
}

data "cloudflare_zone" "dns_zone" {
name = var.traefik_template_values.my_domain
}

resource "cloudflare_record" "main_domain" {
type = "A"
name = var.traefik_template_values.my_domain
zone_id = data.cloudflare_zone.dns_zone.id
proxied = true
value = local.traefik_nlb_public_ip
depends_on = [helm_release.traefik, data.oci_network_load_balancer_network_load_balancers.traefik, data.cloudflare_zone.dns_zone]
}

resource "cloudflare_record" "traefik" {
type = "A"
name = "traefik"
proxied = true
zone_id = data.cloudflare_zone.dns_zone.id
value = local.traefik_nlb_public_ip
depends_on = [helm_release.traefik, data.oci_network_load_balancer_network_load_balancers.traefik, data.cloudflare_zone.dns_zone]
}

resource "cloudflare_record" "wildcard" {
type = "A"
name = "*"
proxied = true
value = local.traefik_nlb_public_ip
zone_id = data.cloudflare_zone.dns_zone.id
depends_on = [helm_release.traefik, data.oci_network_load_balancer_network_load_balancers.traefik, data.cloudflare_zone.dns_zone]
}
4 changes: 4 additions & 0 deletions oci-managed/nlb/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ terraform {
source = "hashicorp/helm"
version = ">= 2.12.1"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}
}
2 changes: 1 addition & 1 deletion oci-managed/nlb/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ variable "traefik_chart_version" {
variable "timeout_seconds" {
type = number
description = "Helm chart deployment can sometimes take longer than the default 5 minutes. Set a custom timeout here."
default = 180 # 10 minutes
default = 800 # 10 minutes
}

variable "replica_count" {
Expand Down
11 changes: 6 additions & 5 deletions oci-managed/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ terraform {
source = "hashicorp/helm"
version = ">= 2.12.1"
}
kubectl = {
source = "gavinbunney/kubectl"
version = ">= 1.14.0"
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}
}
Expand All @@ -30,6 +30,7 @@ provider "helm" {
}
}

provider "kubectl" {
config_path = "oke/kubeconfig"
provider "cloudflare" {
email = var.cloudflare_api_email
api_key = var.cloudflare_api_key
}
11 changes: 8 additions & 3 deletions oci-managed/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ variable "private_key_path" {}
variable "availability_domain" {}
variable "cluster_name" {}

variable "certmanager_email_address" {

variable "cloudflare_api_email" {
type = string
}
variable "cloudflare_email_address" {
variable "cloudflare_api_key" {
type = string
}
variable "cloudflare_api_key" {
variable "cloudflare_origin_certificate_pem" {
type = string
}
variable "cloudflare_origin_certificate_key" {
type = string
}

variable "my_domain" {
type = string
}
Expand Down

0 comments on commit 65ab50b

Please sign in to comment.