diff --git a/README.md b/README.md index 61c431e..082af78 100644 --- a/README.md +++ b/README.md @@ -5,22 +5,18 @@ This repository contains all the Terraform code I use to deploy the infrastructu Folder structure: ``` . -├── hetzner -│   ├── Projects -│   │   ├── Development -│   │   │   └── mailcow -│   │   └── Pterodactyl -│   │   ├── node-01 -│   │   ├── panel -│   │   └── pterodactyl -│   └── template +├── archive +├── dev ├── LICENSE -└── README.md +├── Makefile +├── prd +├── README.md +└── template ``` -`./hetzner/` - projects hosted on Hetzner Cloud -`./*/Projects/` - all my projects in my production environment -`./*/Development/` - all my projects in my development environment -`./hetzner/Projects/Pterodactyl/` - a game server management panel -`./hetzner/Development/mailcow/` - a mailserver suite +`./archive/` - legacy projects +`./dev/` - development environment +`./prd/` - production environment +`./[env]/infra/` - non project-specific infrastructure +`./[env]/projects/` - projects for each environment diff --git a/hetzner/Projects/Development/mailcow/cloud-config.tpl b/archive/hetzner/Projects/Development/mailcow/cloud-config.tpl similarity index 100% rename from hetzner/Projects/Development/mailcow/cloud-config.tpl rename to archive/hetzner/Projects/Development/mailcow/cloud-config.tpl diff --git a/hetzner/Projects/Development/mailcow/firewall.tf b/archive/hetzner/Projects/Development/mailcow/firewall.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/firewall.tf rename to archive/hetzner/Projects/Development/mailcow/firewall.tf diff --git a/hetzner/Projects/Development/mailcow/main.tf b/archive/hetzner/Projects/Development/mailcow/main.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/main.tf rename to archive/hetzner/Projects/Development/mailcow/main.tf diff --git a/hetzner/Projects/Development/mailcow/network.tf b/archive/hetzner/Projects/Development/mailcow/network.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/network.tf rename to archive/hetzner/Projects/Development/mailcow/network.tf diff --git a/hetzner/Projects/Development/mailcow/outputs.tf b/archive/hetzner/Projects/Development/mailcow/outputs.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/outputs.tf rename to archive/hetzner/Projects/Development/mailcow/outputs.tf diff --git a/hetzner/Projects/Development/mailcow/provider.tf b/archive/hetzner/Projects/Development/mailcow/provider.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/provider.tf rename to archive/hetzner/Projects/Development/mailcow/provider.tf diff --git a/hetzner/Projects/Development/mailcow/rdns.tf b/archive/hetzner/Projects/Development/mailcow/rdns.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/rdns.tf rename to archive/hetzner/Projects/Development/mailcow/rdns.tf diff --git a/hetzner/Projects/Development/mailcow/server.tf b/archive/hetzner/Projects/Development/mailcow/server.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/server.tf rename to archive/hetzner/Projects/Development/mailcow/server.tf diff --git a/hetzner/Projects/Development/mailcow/server_network.tf b/archive/hetzner/Projects/Development/mailcow/server_network.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/server_network.tf rename to archive/hetzner/Projects/Development/mailcow/server_network.tf diff --git a/hetzner/Projects/Development/mailcow/subnet.tf b/archive/hetzner/Projects/Development/mailcow/subnet.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/subnet.tf rename to archive/hetzner/Projects/Development/mailcow/subnet.tf diff --git a/hetzner/Projects/Development/mailcow/variables.tf b/archive/hetzner/Projects/Development/mailcow/variables.tf similarity index 100% rename from hetzner/Projects/Development/mailcow/variables.tf rename to archive/hetzner/Projects/Development/mailcow/variables.tf diff --git a/hetzner/Projects/Development/neko/cloud-config.tpl b/archive/hetzner/Projects/Development/neko/cloud-config.tpl similarity index 100% rename from hetzner/Projects/Development/neko/cloud-config.tpl rename to archive/hetzner/Projects/Development/neko/cloud-config.tpl diff --git a/hetzner/Projects/Development/neko/firewall.tf b/archive/hetzner/Projects/Development/neko/firewall.tf similarity index 100% rename from hetzner/Projects/Development/neko/firewall.tf rename to archive/hetzner/Projects/Development/neko/firewall.tf diff --git a/hetzner/Projects/Development/neko/install.sh b/archive/hetzner/Projects/Development/neko/install.sh similarity index 100% rename from hetzner/Projects/Development/neko/install.sh rename to archive/hetzner/Projects/Development/neko/install.sh diff --git a/hetzner/Projects/Development/neko/main.tf b/archive/hetzner/Projects/Development/neko/main.tf similarity index 100% rename from hetzner/Projects/Development/neko/main.tf rename to archive/hetzner/Projects/Development/neko/main.tf diff --git a/hetzner/Projects/Development/neko/network.tf b/archive/hetzner/Projects/Development/neko/network.tf similarity index 100% rename from hetzner/Projects/Development/neko/network.tf rename to archive/hetzner/Projects/Development/neko/network.tf diff --git a/hetzner/Projects/Development/neko/outputs.tf b/archive/hetzner/Projects/Development/neko/outputs.tf similarity index 100% rename from hetzner/Projects/Development/neko/outputs.tf rename to archive/hetzner/Projects/Development/neko/outputs.tf diff --git a/hetzner/Projects/Development/neko/provider.tf b/archive/hetzner/Projects/Development/neko/provider.tf similarity index 100% rename from hetzner/Projects/Development/neko/provider.tf rename to archive/hetzner/Projects/Development/neko/provider.tf diff --git a/hetzner/Projects/Development/neko/server.tf b/archive/hetzner/Projects/Development/neko/server.tf similarity index 100% rename from hetzner/Projects/Development/neko/server.tf rename to archive/hetzner/Projects/Development/neko/server.tf diff --git a/hetzner/Projects/Development/neko/server_network.tf b/archive/hetzner/Projects/Development/neko/server_network.tf similarity index 100% rename from hetzner/Projects/Development/neko/server_network.tf rename to archive/hetzner/Projects/Development/neko/server_network.tf diff --git a/hetzner/Projects/Development/neko/subnet.tf b/archive/hetzner/Projects/Development/neko/subnet.tf similarity index 100% rename from hetzner/Projects/Development/neko/subnet.tf rename to archive/hetzner/Projects/Development/neko/subnet.tf diff --git a/hetzner/Projects/Development/neko/variables.tf b/archive/hetzner/Projects/Development/neko/variables.tf similarity index 100% rename from hetzner/Projects/Development/neko/variables.tf rename to archive/hetzner/Projects/Development/neko/variables.tf diff --git a/hetzner/Projects/Pterodactyl/node-01/cloud-config.tpl b/archive/hetzner/Projects/Pterodactyl/node-01/cloud-config.tpl similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/cloud-config.tpl rename to archive/hetzner/Projects/Pterodactyl/node-01/cloud-config.tpl diff --git a/hetzner/Projects/Pterodactyl/node-01/docker-compose.yml.bak b/archive/hetzner/Projects/Pterodactyl/node-01/docker-compose.yml.bak similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/docker-compose.yml.bak rename to archive/hetzner/Projects/Pterodactyl/node-01/docker-compose.yml.bak diff --git a/hetzner/Projects/Pterodactyl/node-01/firewall.tf b/archive/hetzner/Projects/Pterodactyl/node-01/firewall.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/firewall.tf rename to archive/hetzner/Projects/Pterodactyl/node-01/firewall.tf diff --git a/hetzner/Projects/Pterodactyl/node-01/main.tf b/archive/hetzner/Projects/Pterodactyl/node-01/main.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/main.tf rename to archive/hetzner/Projects/Pterodactyl/node-01/main.tf diff --git a/hetzner/Projects/Pterodactyl/node-01/network.tf b/archive/hetzner/Projects/Pterodactyl/node-01/network.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/network.tf rename to archive/hetzner/Projects/Pterodactyl/node-01/network.tf diff --git a/hetzner/Projects/Pterodactyl/node-01/outputs.tf b/archive/hetzner/Projects/Pterodactyl/node-01/outputs.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/outputs.tf rename to archive/hetzner/Projects/Pterodactyl/node-01/outputs.tf diff --git a/hetzner/Projects/Pterodactyl/node-01/provider.tf b/archive/hetzner/Projects/Pterodactyl/node-01/provider.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/provider.tf rename to archive/hetzner/Projects/Pterodactyl/node-01/provider.tf diff --git a/hetzner/Projects/Pterodactyl/node-01/server.tf b/archive/hetzner/Projects/Pterodactyl/node-01/server.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/server.tf rename to archive/hetzner/Projects/Pterodactyl/node-01/server.tf diff --git a/hetzner/Projects/Pterodactyl/node-01/server_network.tf b/archive/hetzner/Projects/Pterodactyl/node-01/server_network.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/server_network.tf rename to archive/hetzner/Projects/Pterodactyl/node-01/server_network.tf diff --git a/hetzner/Projects/Pterodactyl/node-01/variables.tf b/archive/hetzner/Projects/Pterodactyl/node-01/variables.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/node-01/variables.tf rename to archive/hetzner/Projects/Pterodactyl/node-01/variables.tf diff --git a/hetzner/Projects/Pterodactyl/panel/.terraform.lock.hcl b/archive/hetzner/Projects/Pterodactyl/panel/.terraform.lock.hcl similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/.terraform.lock.hcl rename to archive/hetzner/Projects/Pterodactyl/panel/.terraform.lock.hcl diff --git a/hetzner/Projects/Pterodactyl/panel/cloud-config.tpl b/archive/hetzner/Projects/Pterodactyl/panel/cloud-config.tpl similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/cloud-config.tpl rename to archive/hetzner/Projects/Pterodactyl/panel/cloud-config.tpl diff --git a/hetzner/Projects/Pterodactyl/panel/docker-compose.yml.bak b/archive/hetzner/Projects/Pterodactyl/panel/docker-compose.yml.bak similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/docker-compose.yml.bak rename to archive/hetzner/Projects/Pterodactyl/panel/docker-compose.yml.bak diff --git a/hetzner/Projects/Pterodactyl/panel/firewall.tf b/archive/hetzner/Projects/Pterodactyl/panel/firewall.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/firewall.tf rename to archive/hetzner/Projects/Pterodactyl/panel/firewall.tf diff --git a/hetzner/Projects/Pterodactyl/panel/floating_ip.tf b/archive/hetzner/Projects/Pterodactyl/panel/floating_ip.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/floating_ip.tf rename to archive/hetzner/Projects/Pterodactyl/panel/floating_ip.tf diff --git a/hetzner/Projects/Pterodactyl/panel/main.tf b/archive/hetzner/Projects/Pterodactyl/panel/main.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/main.tf rename to archive/hetzner/Projects/Pterodactyl/panel/main.tf diff --git a/hetzner/Projects/Pterodactyl/panel/network.tf b/archive/hetzner/Projects/Pterodactyl/panel/network.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/network.tf rename to archive/hetzner/Projects/Pterodactyl/panel/network.tf diff --git a/hetzner/Projects/Pterodactyl/panel/outputs.tf b/archive/hetzner/Projects/Pterodactyl/panel/outputs.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/outputs.tf rename to archive/hetzner/Projects/Pterodactyl/panel/outputs.tf diff --git a/hetzner/Projects/Pterodactyl/panel/provider.tf b/archive/hetzner/Projects/Pterodactyl/panel/provider.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/provider.tf rename to archive/hetzner/Projects/Pterodactyl/panel/provider.tf diff --git a/hetzner/Projects/Pterodactyl/panel/server.tf b/archive/hetzner/Projects/Pterodactyl/panel/server.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/server.tf rename to archive/hetzner/Projects/Pterodactyl/panel/server.tf diff --git a/hetzner/Projects/Pterodactyl/panel/server_network.tf b/archive/hetzner/Projects/Pterodactyl/panel/server_network.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/server_network.tf rename to archive/hetzner/Projects/Pterodactyl/panel/server_network.tf diff --git a/hetzner/Projects/Pterodactyl/panel/subnet.tf b/archive/hetzner/Projects/Pterodactyl/panel/subnet.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/subnet.tf rename to archive/hetzner/Projects/Pterodactyl/panel/subnet.tf diff --git a/hetzner/Projects/Pterodactyl/panel/variables.tf b/archive/hetzner/Projects/Pterodactyl/panel/variables.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/panel/variables.tf rename to archive/hetzner/Projects/Pterodactyl/panel/variables.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/.terraform.lock.hcl b/archive/hetzner/Projects/Pterodactyl/pterodactyl/.terraform.lock.hcl similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/.terraform.lock.hcl rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/.terraform.lock.hcl diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/cloud-config.tpl b/archive/hetzner/Projects/Pterodactyl/pterodactyl/cloud-config.tpl similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/cloud-config.tpl rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/cloud-config.tpl diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/docker-compose.yml.bak b/archive/hetzner/Projects/Pterodactyl/pterodactyl/docker-compose.yml.bak similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/docker-compose.yml.bak rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/docker-compose.yml.bak diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/firewall.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/firewall.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/firewall.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/firewall.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/main.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/main.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/main.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/main.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/network.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/network.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/network.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/network.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/outputs.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/outputs.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/outputs.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/outputs.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/provider.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/provider.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/provider.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/provider.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/server.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/server.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/server.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/server.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/server_network.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/server_network.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/server_network.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/server_network.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/subnet.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/subnet.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/subnet.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/subnet.tf diff --git a/hetzner/Projects/Pterodactyl/pterodactyl/variables.tf b/archive/hetzner/Projects/Pterodactyl/pterodactyl/variables.tf similarity index 100% rename from hetzner/Projects/Pterodactyl/pterodactyl/variables.tf rename to archive/hetzner/Projects/Pterodactyl/pterodactyl/variables.tf diff --git a/archive/hetzner/template/backend.tf b/archive/hetzner/template/backend.tf new file mode 100644 index 0000000..395754d --- /dev/null +++ b/archive/hetzner/template/backend.tf @@ -0,0 +1,9 @@ +terraform { + backend "s3" { + region = "main" + skip_credentials_validation = true + skip_metadata_api_check = true + skip_region_validation = true + force_path_style = true + } +} \ No newline at end of file diff --git a/archive/hetzner/template/firewall.tf b/archive/hetzner/template/firewall.tf new file mode 100644 index 0000000..404cabf --- /dev/null +++ b/archive/hetzner/template/firewall.tf @@ -0,0 +1,6 @@ +module "firewall" { + source = "./modules/firewall" + firewall_name = "fw-${var.project_name}" + firewall_service_type = "Basic" + firewall_labels = local.common_labels +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/firewall/firewall.tf b/archive/hetzner/template/modules/firewall/firewall.tf new file mode 100644 index 0000000..ff8094f --- /dev/null +++ b/archive/hetzner/template/modules/firewall/firewall.tf @@ -0,0 +1,21 @@ +resource "hcloud_firewall" "firewall" { + name = var.firewall_name + labels = merge( + var.firewall_labels, + { + "Resource_Type" = "Firewall" + "Service_Type" = var.firewall_service_type + } + ) + + dynamic "rule" { + for_each = local.rule_set + content { + description = rule.value["description"] + direction = rule.value["direction"] + port = rule.value["port"] + protocol = rule.value["protocol"] + source_ips = rule.value["source_ips"] + } + } +} diff --git a/archive/hetzner/template/modules/firewall/firewall_attachment.tf b/archive/hetzner/template/modules/firewall/firewall_attachment.tf new file mode 100644 index 0000000..8565cb9 --- /dev/null +++ b/archive/hetzner/template/modules/firewall/firewall_attachment.tf @@ -0,0 +1,4 @@ +resource "hcloud_firewall_attachment" "firewall_attachment" { + firewall_id = hcloud_firewall.firewall.id + label_selectors = ["Service_Type = ${var.firewall_service_type}"] +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/firewall/outputs.tf b/archive/hetzner/template/modules/firewall/outputs.tf new file mode 100644 index 0000000..d5cfcef --- /dev/null +++ b/archive/hetzner/template/modules/firewall/outputs.tf @@ -0,0 +1,3 @@ +output "firewall_id" { + value = hcloud_firewall.firewall.id +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/firewall/variables.tf b/archive/hetzner/template/modules/firewall/variables.tf new file mode 100644 index 0000000..bfd2a79 --- /dev/null +++ b/archive/hetzner/template/modules/firewall/variables.tf @@ -0,0 +1,70 @@ +variable "firewall_labels" { + description = "Labels to be associated to resource" + type = map(string) +} + +variable "firewall_name" { + description = "Name of resource" + type = string +} + +variable "firewall_service_type" { + description = "The 'Service_Type label the firewall targets" + type = string + +} + +# Define individual rules +locals { + ssh_firewall_rule = { + description = "SSH IN" + direction = "in" + protocol = "tcp" + port = 22 + source_ips = [ + "0.0.0.0/0", + "::/0" + ] + } + http_firewall_rule = { + description = "HTTP IN" + direction = "in" + protocol = "tcp" + port = 80 + source_ips = [ + "0.0.0.0/0", + "::/0" + ] + } + https_firewall_rule = { + description = "HTTPS IN" + direction = "in" + protocol = "tcp" + port = 443 + source_ips = [ + "0.0.0.0/0", + "::/0" + ] + } +} + +# Define rule groups +locals { + basic_firewall_rules = [local.ssh_firewall_rule] + web_firewall_rules = [ + local.basic_firewall_rules, + local.http_firewall_rule, + local.https_firewall_rule] +} + +# Select rule group based on passed variable +locals { + rule_set = lookup( + { + Web = local.web_firewall_rules, + Basic = local.basic_firewall_rules + }, + var.firewall_service_type, + local.basic_firewall_rules + ) +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/firewall/versions.tf b/archive/hetzner/template/modules/firewall/versions.tf new file mode 100644 index 0000000..9b89ead --- /dev/null +++ b/archive/hetzner/template/modules/firewall/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + hcloud = { + source = "hetznercloud/hcloud" + version = "~> 1.41.0" + } + } +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/server/data.tf b/archive/hetzner/template/modules/server/data.tf new file mode 100644 index 0000000..f7cdf69 --- /dev/null +++ b/archive/hetzner/template/modules/server/data.tf @@ -0,0 +1,3 @@ +data "hcloud_ssh_key" "ansible_provision_key" { + name = "Ansible Provisioner" +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/server/outputs.tf b/archive/hetzner/template/modules/server/outputs.tf new file mode 100644 index 0000000..ab16d49 --- /dev/null +++ b/archive/hetzner/template/modules/server/outputs.tf @@ -0,0 +1,15 @@ +output "server_public_ipv4" { + value = hcloud_server.server.ipv4_address +} + +output "server_public_ipv6" { + value = hcloud_server.server.ipv6_address +} + +output "server_private_ipv4" { + value = hcloud_server_network.server_network.ip +} + +output "server_name" { + value = hcloud_server.server.name +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/server/primary_ip.tf b/archive/hetzner/template/modules/server/primary_ip.tf new file mode 100644 index 0000000..2e6351b --- /dev/null +++ b/archive/hetzner/template/modules/server/primary_ip.tf @@ -0,0 +1,23 @@ +# resource "hcloud_primary_ip" "main_ipv4" { +# name = "pip-${var.server_name}-ipv4" +# type = "ipv4" +# assignee_type = "server" +# auto_delete = false +# assignee_id = hcloud_server.server.id +# labels = merge( +# var.labels, +# { "Resource_Type" = "Primary_IP" } +# ) +# } + +# resource "hcloud_primary_ip" "main_ipv6" { +# name = "pip-${var.server_name}-ipv6" +# type = "ipv6" +# assignee_type = "server" +# assignee_id = hcloud_server.server.id +# auto_delete = false +# labels = merge( +# var.labels, +# { "Resource_Type" = "Primary_IP" } +# ) +# } \ No newline at end of file diff --git a/archive/hetzner/template/modules/server/server.tf b/archive/hetzner/template/modules/server/server.tf new file mode 100644 index 0000000..c0a3c2b --- /dev/null +++ b/archive/hetzner/template/modules/server/server.tf @@ -0,0 +1,19 @@ +resource "hcloud_server" "server" { + name = "vm-${var.server_name}" + server_type = var.server_type + image = var.server_image + location = var.server_location + backups = var.server_backups + ssh_keys = [data.hcloud_ssh_key.ansible_provision_key.id] + labels = merge( + var.labels, + { + "Resource_Type" = "Virtual_Machine" + "Service_Type" = var.service_type + } + ) + public_net { + ipv4_enabled = true + ipv6_enabled = true + } +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/server/server_network.tf b/archive/hetzner/template/modules/server/server_network.tf new file mode 100644 index 0000000..3d56497 --- /dev/null +++ b/archive/hetzner/template/modules/server/server_network.tf @@ -0,0 +1,5 @@ +resource "hcloud_server_network" "server_network" { + server_id = hcloud_server.server.id + network_id = var.server_network_id + ip = var.server_private_ipv4 +} diff --git a/archive/hetzner/template/modules/server/variables.tf b/archive/hetzner/template/modules/server/variables.tf new file mode 100644 index 0000000..2094060 --- /dev/null +++ b/archive/hetzner/template/modules/server/variables.tf @@ -0,0 +1,35 @@ +variable "server_name" { + type = string +} + +variable "server_type" { + type = string +} + +variable "server_image" { + type = string +} + +variable "server_location" { + type = string +} + +variable "server_backups" { + type = string +} + +variable "labels" { + type = map(string) +} + +variable "server_private_ipv4" { + type = string +} + +variable "server_network_id" { + type = string +} + +variable "service_type" { + type = string +} \ No newline at end of file diff --git a/archive/hetzner/template/modules/server/versions.tf b/archive/hetzner/template/modules/server/versions.tf new file mode 100644 index 0000000..9b89ead --- /dev/null +++ b/archive/hetzner/template/modules/server/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + hcloud = { + source = "hetznercloud/hcloud" + version = "~> 1.41.0" + } + } +} \ No newline at end of file diff --git a/archive/hetzner/template/network.tf b/archive/hetzner/template/network.tf new file mode 100644 index 0000000..257f9a3 --- /dev/null +++ b/archive/hetzner/template/network.tf @@ -0,0 +1,15 @@ +resource "hcloud_network" "network" { + name = "vnet-${var.project_name}" + ip_range = "10.0.0.0/16" + labels = merge( + local.common_labels, + { "Resource_Type" = "Virtual_Network" } + ) +} + +resource "hcloud_network_subnet" "subnet" { + network_id = hcloud_network.network.id + type = "cloud" + ip_range = "10.0.1.0/24" + network_zone = "eu-central" +} \ No newline at end of file diff --git a/archive/hetzner/template/outputs.tf b/archive/hetzner/template/outputs.tf new file mode 100644 index 0000000..bb83a9b --- /dev/null +++ b/archive/hetzner/template/outputs.tf @@ -0,0 +1,7 @@ +output "public_ip" { + value = module.server.server_public_ipv4 +} + +output "private_ip" { + value = module.server.server_private_ipv4 +} diff --git a/hetzner/Projects/Development/landing-zone/provider.tf b/archive/hetzner/template/provider.tf similarity index 54% rename from hetzner/Projects/Development/landing-zone/provider.tf rename to archive/hetzner/template/provider.tf index 90dc159..706ed68 100644 --- a/hetzner/Projects/Development/landing-zone/provider.tf +++ b/archive/hetzner/template/provider.tf @@ -1,4 +1,3 @@ -# Configure the Hetzner Cloud Provider provider "hcloud" { token = var.hcloud_token -} \ No newline at end of file +} diff --git a/archive/hetzner/template/server.tf b/archive/hetzner/template/server.tf new file mode 100644 index 0000000..67be5ab --- /dev/null +++ b/archive/hetzner/template/server.tf @@ -0,0 +1,12 @@ +module "server" { + source = "./modules/server" + server_name = "node-001" + server_type = "cx11" + server_image = "debian-12" + server_location = var.location + server_backups = true + server_private_ipv4 = "10.0.1.1" + server_network_id = hcloud_network.network.id + service_type = "Basic" + labels = local.common_labels +} \ No newline at end of file diff --git a/archive/hetzner/template/variables.tf b/archive/hetzner/template/variables.tf new file mode 100644 index 0000000..98a3a7b --- /dev/null +++ b/archive/hetzner/template/variables.tf @@ -0,0 +1,36 @@ +variable "hcloud_token" { + type = string + sensitive = true +} + +variable "environment" { + type = string +} + +variable "project_name" { + type = string + default = "project" +} + +variable "location" { + type = string + default = "nbg1" +} + +locals { + environment_long = lookup( + { + dev = "Development", + tst = "Test", + prd = "Production" + }, + var.environment, + "Development" + ) + + common_labels = { + "Project" = var.project_name + "Owner" = "Oscar" + "Environment" = local.environment_long + } +} \ No newline at end of file diff --git a/archive/hetzner/template/versions.tf b/archive/hetzner/template/versions.tf new file mode 100644 index 0000000..538965d --- /dev/null +++ b/archive/hetzner/template/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.5.2" + required_providers { + hcloud = { + source = "hetznercloud/hcloud" + version = "~> 1.41.0" + } + } +} \ No newline at end of file diff --git a/hetzner/Projects/Development/landing-zone/.terraform.lock.hcl b/hetzner/Projects/Development/landing-zone/.terraform.lock.hcl deleted file mode 100644 index 985890d..0000000 --- a/hetzner/Projects/Development/landing-zone/.terraform.lock.hcl +++ /dev/null @@ -1,24 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hetznercloud/hcloud" { - version = "1.36.1" - constraints = "~> 1.36.0" - hashes = [ - "h1:xZSvxx6aUo0oZp2uqNxi/+wqnCNEBBuu8y7GeXIO9qA=", - "zh:16558b25c7f92f187278e94e951b0ab687882b06acff5b1387f3293f27939f8c", - "zh:28fc79ac2189ff0f5e6c9535ada8f57552b6e21c978b59dc78e086c27b9e4b23", - "zh:373907f9f7f2cefa94e2d5638bf5bef3d3b17e7655dc84dd6089346c6f4f9096", - "zh:394716cd877de682a0772d660f1bdb3838c5d751eca2211105d5ede248c48c39", - "zh:3c438c6590fcc8ac65a10039b2f5ba9ee379a734cb93a59c6cf74f385d891e87", - "zh:3f777a460a62fd23b283c269f1533b3887bf0c5564581e1e96cf294e077f5a8a", - "zh:4f62967553d7ce81ec14db7685306b625970ba6640b5764dc0137675ab97af0b", - "zh:56da08f8d75f596d6f9da4f0fd16bd60d1733cabcc260e885e1d7a711d6d3d8b", - "zh:62776c885bfa8e715dba6662f1744b5251f4cdd523dd4d1e4ccb2e25489593e9", - "zh:64cbb68139aa65f95ab3e654d872f9d34ef991fbf667fc30e0f29b96b5e8b4ed", - "zh:75a4b7a73ff0a537214d12d820438b7ae7a33d660e5d793f4ae0ebe3152bff00", - "zh:7b59d72538772ada7d51eaa50c905285200b1889ab29948b533412ccdf4d18de", - "zh:b84eeaa82bf765c6dd945ae83f1a9271fa5fad53b861b18b09cb8deda67dae13", - "zh:e81c3ea971e32a6ca3fdb0cd9e644614308ab2cf2a19482dd8a109d67fe3fb6f", - ] -} diff --git a/hetzner/Projects/Development/landing-zone/backend.tf b/hetzner/Projects/Development/landing-zone/backend.tf deleted file mode 100644 index 14e8192..0000000 --- a/hetzner/Projects/Development/landing-zone/backend.tf +++ /dev/null @@ -1,17 +0,0 @@ -terraform { - backend "s3" { - bucket = "tf-state-oscar" - key = "terraform.tfstate" - region = "us-east-1" - endpoint = "s3.eu-central-003.backblazeb2.com" - access_key = "xxxx" - secret_key = "xxxx" - - skip_requesting_account_id = true - skip_credentials_validation = true - skip_get_ec2_platforms = true - skip_metadata_api_check = true - skip_region_validation = true - - } -} \ No newline at end of file diff --git a/hetzner/Projects/Development/landing-zone/main.tf b/hetzner/Projects/Development/landing-zone/main.tf deleted file mode 100644 index cd90f6a..0000000 --- a/hetzner/Projects/Development/landing-zone/main.tf +++ /dev/null @@ -1,10 +0,0 @@ -# Create a new server running debian -resource "hcloud_server" "node1" { - name = "node1" - image = "debian-11" - server_type = "cx11" - public_net { - ipv4_enabled = true - ipv6_enabled = true - } -} \ No newline at end of file diff --git a/hetzner/Projects/Development/landing-zone/variables.tf b/hetzner/Projects/Development/landing-zone/variables.tf deleted file mode 100644 index e7c25e6..0000000 --- a/hetzner/Projects/Development/landing-zone/variables.tf +++ /dev/null @@ -1,5 +0,0 @@ -# Set the variable value in *.tfvars file -# or using the -var="hcloud_token=..." CLI option -variable "hcloud_token" { - sensitive = true # Requires terraform >= 0.14 -} \ No newline at end of file diff --git a/hetzner/Projects/Development/landing-zone/versions.tf b/hetzner/Projects/Development/landing-zone/versions.tf deleted file mode 100644 index 7222126..0000000 --- a/hetzner/Projects/Development/landing-zone/versions.tf +++ /dev/null @@ -1,9 +0,0 @@ -terraform { - required_providers { - hcloud = { - source = "hetznercloud/hcloud" - version = "~> 1.36.0" - } - } - required_version = ">= 1.3.6" -} \ No newline at end of file diff --git a/hetzner/Projects/Development/neko/.terraform.lock.hcl b/hetzner/Projects/Development/neko/.terraform.lock.hcl deleted file mode 100644 index ed70c08..0000000 --- a/hetzner/Projects/Development/neko/.terraform.lock.hcl +++ /dev/null @@ -1,24 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hetznercloud/hcloud" { - version = "1.35.1" - constraints = "~> 1.35.1" - hashes = [ - "h1:FgSVN8CkqWt+iHhTYPPVQgoltoO8FGI+quB0PZucfj4=", - "zh:055161a3bec0b09db32b2488ac9036e46e7867c3319af182329157a1ff72ca00", - "zh:08f0d5b31dfac682df21a3f193aac93522a05e83e8eca26c547d2baa2858238b", - "zh:16d4c4a194d056947820680a116bf23227d4ee527d33831d7a7df52c5c0c3c4b", - "zh:46b528a76968599e1a6c45d8264b86fe9602070a42fd2d2db32899b5161e44dc", - "zh:502b16a56bb6780b86913ad3f4f573ae3f29f7a3d99335d7fd120c1b607537e8", - "zh:5fa5114d101e9d7c1915b1f136cc2b48a83c9ace7c994545940f11ccabf1f036", - "zh:6ac8ff28f145ef20c595faf81ff9c478be4d469cdd5b7aeaf2feefcc80a3dd36", - "zh:8ced6aec0546784eea6a9e56082af3af5c9917459351ef2951a9742125d4aab9", - "zh:927b0c39de0b368e52c7491859948082aaa84d877f0fed7ef483892c844875bf", - "zh:9d9c0fb5e862e47d24cdb007afad0215ccff9da65cf8a6cfa66030e844f5403c", - "zh:ae5475cae11806a93bb4adb3c87007ce9c0211d16c9c7a87ae5e9d58a68fcc0b", - "zh:d01600e67abc7ce7c59bc8567b7a650bc5ce817723a354f401a803d421610641", - "zh:f3487f1c49145b560fd19c8c681cb9eaaa85fc3700ea9b675f649f5f5d8b1e3c", - "zh:f5257b83287156effecb0f43fe80b6cbcc02c89f35ceda1b845d4e3dcf757dca", - ] -}