Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing preview deployment #18

Open
wants to merge 9 commits into
base: staging
Choose a base branch
from
Prev Previous commit
Next Next commit
Better naming on Hetzner
  • Loading branch information
sjmog committed Sep 27, 2024
commit 9430d9e9cbdfef78fe70a5ee370c57ccab2b156c
3 changes: 3 additions & 0 deletions bin/provision
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export TF_VAR_subdomain="$(read_from_infrastructure $ENVIRONMENT subdomain)"
export TF_VAR_ssh_key_name="${TF_VAR_subdomain}.${TF_VAR_domain_name}-ssh-key-${ENVIRONMENT}"
export TF_VAR_network_name="${TF_VAR_subdomain}.${TF_VAR_domain_name}-network-${ENVIRONMENT}"
export TF_VAR_load_balancer_name="${TF_VAR_subdomain}.${TF_VAR_domain_name}-lb-${ENVIRONMENT}"
export TF_VAR_firewall_name="${TF_VAR_subdomain}.${TF_VAR_domain_name}-firewall-${ENVIRONMENT}"
export TF_VAR_web_server_prefix="${TF_VAR_subdomain}.${TF_VAR_domain_name}-${ENVIRONMENT}"
export TF_VAR_accessories_server_prefix="${TF_VAR_subdomain}.${TF_VAR_domain_name}-${ENVIRONMENT}"

echo "Terraform variables exported as environment variables"

Expand Down
16 changes: 8 additions & 8 deletions terraform/hetzner.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "hcloud_network_subnet" "network_subnet" {

resource "hcloud_server" "web" {
count = var.web_servers_count
name = var.web_servers_count > 1 ? "web-${count.index + 1}" : "web"
name = var.web_servers_count > 1 ? "${var.web_server_prefix}-web-${count.index + 1}" : "${var.web_server_prefix}-web"
image = var.operating_system
server_type = var.server_type
location = var.region
Expand Down Expand Up @@ -49,7 +49,7 @@ resource "hcloud_server" "web" {

resource "hcloud_server" "accessories" {
count = var.accessories_count
name = var.accessories_count > 1 ? "accessories-${count.index + 1}" : "accessories"
name = var.accessories_count > 1 ? "${var.accessories_server_prefix}-accessories-${count.index + 1}" : "${var.accessories_server_prefix}-accessories"
image = var.operating_system
server_type = var.server_type
location = var.region
Expand Down Expand Up @@ -81,7 +81,7 @@ resource "hcloud_server" "accessories" {

resource "hcloud_load_balancer" "web_load_balancer" {
count = var.web_servers_count > 1 ? 1 : 0
name = "web-load-balancer"
name = var.load_balancer_name
load_balancer_type = "lb11"
location = var.region
}
Expand Down Expand Up @@ -132,8 +132,8 @@ resource "hcloud_load_balancer_network" "load_balancer_network" {
]
}

resource "hcloud_firewall" "block_all_except_ssh" {
name = "allow-ssh"
resource "hcloud_firewall" "allow_ssh" {
name = "${var.firewall_name}-allow-ssh"
rule {
direction = "in"
protocol = "tcp"
Expand All @@ -150,7 +150,7 @@ resource "hcloud_firewall" "block_all_except_ssh" {
}

resource "hcloud_firewall" "allow_http_https_from_cloudflare" {
name = "allow-http-https-from-cloudflare"
name = "${var.firewall_name}-allow-http-https-from-cloudflare"
rule {
direction = "in"
protocol = "icmp"
Expand Down Expand Up @@ -215,8 +215,8 @@ resource "hcloud_firewall" "allow_http_https_from_cloudflare" {
}
}

resource "hcloud_firewall" "block_all_inboud_traffic" {
name = "block-inboud_traffic"
resource "hcloud_firewall" "block_all_inbound_traffic" {
name = "${var.firewall_name}-block-inbound-traffic"
# Empty rule blocks all inbound traffic
apply_to {
label_selector = "ssh=no"
Expand Down
20 changes: 12 additions & 8 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,35 @@ variable "subdomain" {
variable "ssh_key_name" {
description = "Name of the SSH key"
default = "boiler-ssh-key"
type = string
}

variable "network_name" {
description = "Name of the network"
default = "boiler-network"
type = string
}

variable "load_balancer_name" {
description = "Name of the load balancer"
default = "boiler-lb"
type = string
}

# Add similar variables for firewalls and other resources

variable "ssh_key_name" {
description = "Name of the SSH key"
variable "firewall_name" {
description = "Name of the firewall"
default = "boiler-firewall"
type = string
}

variable "network_name" {
description = "Name of the network"
variable "web_server_prefix" {
description = "Prefix for the web server"
default = "boiler"
type = string
}

variable "load_balancer_name" {
description = "Name of the load balancer"
variable "accessories_server_prefix" {
description = "Prefix for the accessories server"
default = "boiler"
type = string
}
Loading