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
}
variable "godaddy_key" {
variable "cloudflare_api_token" {
type = string
}
variable "godaddy_secret" {
variable "cloudflare_zone_id" {
type = string
}

View File

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

14
main.tf
View File

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