Merge pull request #41 from HideyoshiSolutions/cloudflare-dns-implementation

Initial Cloudflare Implementation
This commit is contained in:
2024-06-30 02:47:14 -03:00
committed by GitHub
3 changed files with 33 additions and 30 deletions

View File

@@ -35,11 +35,11 @@ variable "aws_secret" {
type = string type = string
} }
variable "godaddy_key" { variable "cloudflare_api_token" {
type = string type = string
} }
variable "godaddy_secret" { variable "cloudflare_zone_id" {
type = string type = string
} }

View File

@@ -1,8 +1,8 @@
terraform { terraform {
required_providers { required_providers {
godaddy = { cloudflare = {
source = "zaneatwork/godaddy" source = "cloudflare/cloudflare"
version = "1.9.10" version = "~> 4.0"
} }
} }
} }
@@ -16,25 +16,28 @@ variable "environment_name" {
type = string type = string
} }
variable "cloudflare_zone_id" {
resource "godaddy_domain_record" "default" { type = string
domain = "hideyoshi.com.br" }
overwrite = false
resource "cloudflare_record" "default" {
record { zone_id = var.cloudflare_zone_id
name = var.environment_name == "prod" ? "@" : "staging"
type = "A" name = var.environment_name == "prod" ? "@" : "staging"
data = "${var.public_ip}" value = var.public_ip
ttl = 600 type = "A"
priority = 0 ttl = 3600
} proxied = false
}
record {
name = var.environment_name == "prod" ? "api" : "api.staging"
type = "A" resource "cloudflare_record" "api" {
data = "${var.public_ip}" zone_id = var.cloudflare_zone_id
ttl = 600
priority = 0 name = var.environment_name == "prod" ? "api" : "api.staging"
} value = var.public_ip
type = "A"
ttl = 3600
proxied = false
} }

14
main.tf
View File

@@ -2,9 +2,9 @@
terraform { terraform {
required_providers { required_providers {
godaddy = { cloudflare = {
source = "zaneatwork/godaddy" source = "cloudflare/cloudflare"
version = "1.9.10" version = "~> 4.0"
} }
aws = { aws = {
source = "hashicorp/aws" source = "hashicorp/aws"
@@ -19,9 +19,8 @@ provider "aws" {
secret_key = var.aws_secret secret_key = var.aws_secret
} }
provider "godaddy" { provider "cloudflare" {
key = var.godaddy_key api_token = var.cloudflare_api_token
secret = var.godaddy_secret
} }
@@ -53,8 +52,9 @@ module "instances" {
module "dns" { module "dns" {
source = "./dns" source = "./dns"
providers = { providers = {
godaddy = godaddy cloudflare = cloudflare
} }
public_ip = module.instances.pool_master_public_ip public_ip = module.instances.pool_master_public_ip
environment_name = var.environment_name environment_name = var.environment_name
cloudflare_zone_id = var.cloudflare_zone_id
} }