-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Cloudflare lb and lb pool creation to modules
- Loading branch information
Showing
15 changed files
with
167 additions
and
48 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,24 @@ | ||
resource "cloudflare_load_balancer" "load_balancer" { | ||
zone_id = data.cloudflare_zone.dns_zone.id | ||
name = "${var.subdomain}.${var.domain_name}" | ||
default_pool_ids = var.pool_ids | ||
fallback_pool_id = var.pool_ids[var.default_pool_ids_index] | ||
description = "${var.subdomain} load balancer using proximity steering policy" | ||
|
||
proxied = false | ||
steering_policy = "proximity" | ||
|
||
location_strategy { | ||
mode = "pop" | ||
prefer_ecs = "proximity" | ||
} | ||
} | ||
|
||
resource "cloudflare_load_balancer_monitor" "monitor" { | ||
account_id = var.cloudflare_account_id | ||
type = "tcp" | ||
port = var.monitoring_port | ||
interval = 60 | ||
timeout = 5 | ||
retries = 2 | ||
} |
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 @@ | ||
data "cloudflare_zone" "dns_zone" { | ||
name = var.domain_name | ||
} |
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 @@ | ||
output "load_balancer_endpoint" { | ||
value = cloudflare_load_balancer.load_balancer.name | ||
} | ||
|
||
output "load_balancer_monitor_id" { | ||
value = cloudflare_load_balancer_monitor.monitor.id | ||
} |
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,30 @@ | ||
variable "cloudflare_account_id" { | ||
description = "Cloudflare Account Id" | ||
type = string | ||
} | ||
|
||
variable "domain_name" { | ||
description = "Domain name for the load balancer" | ||
type = string | ||
} | ||
|
||
variable "subdomain" { | ||
description = "Subdomain for the load balancer" | ||
type = string | ||
} | ||
|
||
variable "pool_ids" { | ||
description = "List of Cloudflare Load Balancer Pool Ids" | ||
type = list(string) | ||
} | ||
|
||
variable "default_pool_ids_index" { | ||
description = "Index of the default pool in the pool_ids list" | ||
type = number | ||
default = 0 | ||
} | ||
|
||
variable "monitoring_port" { | ||
description = "Port used for monitoring by the load balancer" | ||
type = number | ||
} |
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,8 @@ | ||
terraform { | ||
required_providers { | ||
cloudflare = { | ||
source = "cloudflare/cloudflare" | ||
version = "~> 4.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,18 @@ | ||
resource "cloudflare_load_balancer_pool" "pool" { | ||
account_id = var.cloudflare_account_id | ||
name = "${var.pool_name}-${var.region}" | ||
description = "${var.pool_name} pool for ${var.region}" | ||
latitude = var.pool_latitude | ||
longitude = var.pool_longitude | ||
monitor = var.load_balancer_monitor_id | ||
|
||
origins { | ||
name = "${var.pool_name}-${var.region}-pool" | ||
address = var.pool_endpoint | ||
weight = 1 | ||
} | ||
|
||
origin_steering { | ||
policy = "random" | ||
} | ||
} |
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 @@ | ||
output "load_balancer_pool_id" { | ||
value = cloudflare_load_balancer_pool.pool.id | ||
} |
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,34 @@ | ||
variable "region" { | ||
description = "AWS region associated with the resources of the Cloudflare Load Balancer Pool" | ||
type = string | ||
} | ||
|
||
variable "cloudflare_account_id" { | ||
description = "Cloudflare Account Id" | ||
type = string | ||
} | ||
|
||
variable "pool_name" { | ||
description = "Cloudflare Load Balancer Pool Name" | ||
type = string | ||
} | ||
|
||
variable "pool_latitude" { | ||
description = "Cloudflare Load Balancer Pool Latitude" | ||
type = number | ||
} | ||
|
||
variable "pool_longitude" { | ||
description = "Cloudflare Load Balancer Pool Longitude" | ||
type = number | ||
} | ||
|
||
variable "pool_endpoint" { | ||
description = "Cloudflare Load Balancer Pool Endpoint" | ||
type = string | ||
} | ||
|
||
variable "load_balancer_monitor_id" { | ||
description = "Cloudflare Load Balancer Monitor Id" | ||
type = string | ||
} |
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,8 @@ | ||
terraform { | ||
required_providers { | ||
cloudflare = { | ||
source = "cloudflare/cloudflare" | ||
version = "~> 4.0" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
output "endpoint" { | ||
description = "Endpoint of the Stun server" | ||
value = cloudflare_load_balancer.stun-server.name | ||
value = module.cloudflare_load_balancer.load_balancer_endpoint | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
output "cloudflare_load_balancer_pool_id" { | ||
description = "The ID of the Cloudflare Load Balancer Pool" | ||
value = cloudflare_load_balancer_pool.stun-server.id | ||
description = "Cloudflare Load Balancer Pool Id" | ||
value = module.cloudflare_load_balancer_pool.load_balancer_pool_id | ||
} |