feat(infra): add nginx node, random password, null_resource automation, and outputs

This commit is contained in:
Richard
2026-07-29 09:10:22 +02:00
parent 5d0f008f6b
commit d6ebabce8b
5 changed files with 144 additions and 27 deletions
+14 -2
View File
@@ -1,3 +1,8 @@
resource "random_password" "demo_pass" {
length = 16
special = true
}
resource "local_file" "ansible_inventory" { resource "local_file" "ansible_inventory" {
filename = "${path.module}/inventory.ini" filename = "${path.module}/inventory.ini"
file_permission = "0644" file_permission = "0644"
@@ -6,12 +11,18 @@ resource "local_file" "ansible_inventory" {
ansible_ssh_extra_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' ansible_ssh_extra_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
private_ip_caddy='${gridscale_server.server_caddy.network[1].auto_assigned_ip}' private_ip_caddy='${gridscale_server.server_caddy.network[1].auto_assigned_ip}'
private_ip_monitoring='${gridscale_server.server_monitoring.network[1].auto_assigned_ip}' private_ip_monitoring='${gridscale_server.server_monitoring.network[1].auto_assigned_ip}'
private_ip_nginx='${gridscale_server.server_nginx.network[1].auto_assigned_ip}'
demo_pass="${random_password.demo_pass.result}"
demo_user="demo"
[caddy] [caddy]
${var.caddy_hostname} ansible_host=${gridscale_ipv4.public_ipv4.ip} ansible_user=root ${var.caddy_hostname} ansible_host=${gridscale_ipv4.public_ipv4_caddy.ip} ansible_user=root
[monitoring] [monitoring]
${var.monitoring_hostname} ansible_host=${gridscale_ipv4.public_ipv4_monitoring.ip} ansible_user=root ${var.monitoring_hostname} ansible_host=${gridscale_ipv4.public_ipv4_monitoring.ip} ansible_user=root
[nginx]
${var.nginx_hostname} ansible_host=${gridscale_ipv4.public_ipv4_nginx.ip} ansible_user=root
EOT EOT
} }
@@ -19,7 +30,8 @@ resource "null_resource" "ansible_provisioner" {
depends_on = [ depends_on = [
local_file.ansible_inventory, local_file.ansible_inventory,
gridscale_server.server_caddy, gridscale_server.server_caddy,
gridscale_server.server_monitoring gridscale_server.server_monitoring,
gridscale_server.server_nginx
] ]
provisioner "local-exec" { provisioner "local-exec" {
+20 -4
View File
@@ -1,6 +1,6 @@
output "caddy_public_ip" { output "caddy_public_ip" {
description = "Public IPv4 address of the Caddy server" description = "Public IPv4 address of the Caddy server"
value = gridscale_ipv4.public_ipv4.ip value = gridscale_ipv4.public_ipv4_caddy.ip
} }
output "monitoring_public_ip" { output "monitoring_public_ip" {
@@ -8,6 +8,11 @@ output "monitoring_public_ip" {
value = gridscale_ipv4.public_ipv4_monitoring.ip value = gridscale_ipv4.public_ipv4_monitoring.ip
} }
output "nginx_public_ip" {
description = "Public IPv4 address of the Nginx server"
value = gridscale_ipv4.public_ipv4_nginx.ip
}
output "caddy_private_ip" { output "caddy_private_ip" {
description = "Private IPv4 address of the Caddy server" description = "Private IPv4 address of the Caddy server"
value = gridscale_server.server_caddy.network[1].auto_assigned_ip value = gridscale_server.server_caddy.network[1].auto_assigned_ip
@@ -18,7 +23,18 @@ output "monitoring_private_ip" {
value = gridscale_server.server_monitoring.network[1].auto_assigned_ip value = gridscale_server.server_monitoring.network[1].auto_assigned_ip
} }
output "ansible_inventory" { output "nginx_private_ip" {
description = "Generated Ansible inventory content" description = "Private IPv4 address of the Nginx server"
value = local_file.ansible_inventory.content value = gridscale_server.server_nginx.network[1].auto_assigned_ip
}
output "website_urls" {
description = "Website URLs"
value = [
"Caddy: https://caddy.${replace(gridscale_ipv4.public_ipv4_caddy.ip, ".", "-")}.sslip.io",
"Nginx behind Caddy: https://nginx.${replace(gridscale_ipv4.public_ipv4_caddy.ip, ".", "-")}.sslip.io",
"Prometheus behind Caddy: https://monitoring.${replace(gridscale_ipv4.public_ipv4_caddy.ip, ".", "-")}.sslip.io",
"Login for Monitoring: demo ${nonsensitive(random_password.demo_pass.result)}"
]
} }
+19
View File
@@ -115,3 +115,22 @@
src: prometheus.yml.j2 src: prometheus.yml.j2
dest: /etc/prometheus/prometheus.yml dest: /etc/prometheus/prometheus.yml
mode: "0644" mode: "0644"
- name: Configure Nginx Server
hosts: nginx
become: true
tags:
- nginx
tasks:
- name: Install Nginx
ansible.builtin.apt:
pkg:
- nginx
state: present
- name: Create Hello World page
ansible.builtin.template:
src: index.html.j2
dest: /var/www/html/index.html
mode: "0644"
+84 -20
View File
@@ -7,12 +7,12 @@ resource "gridscale_network" "network_internal"{
dhcp_reserved_subnet = ["192.168.121.0/31"] dhcp_reserved_subnet = ["192.168.121.0/31"]
} }
resource "gridscale_ipv4" "public_ipv4" { resource "gridscale_ipv4" "public_ipv4_caddy" {
name = "public_ipv4" name = "public_ipv4_caddy"
} }
resource "gridscale_ipv6" "public_ipv6" { resource "gridscale_ipv6" "public_ipv6_caddy" {
name = "public_ipv6" name = "public_ipv6_caddy"
} }
resource "gridscale_ipv4" "public_ipv4_monitoring" { resource "gridscale_ipv4" "public_ipv4_monitoring" {
@@ -23,6 +23,14 @@ resource "gridscale_ipv6" "public_ipv6_monitoring" {
name = "public_ipv6_monitoring" name = "public_ipv6_monitoring"
} }
resource "gridscale_ipv4" "public_ipv4_nginx" {
name = "public_ipv4_nginx"
}
resource "gridscale_ipv6" "public_ipv6_nginx" {
name = "public_ipv6_nginx"
}
data "gridscale_template" "template_debian_13" { data "gridscale_template" "template_debian_13" {
name = "Debian 13" name = "Debian 13"
} }
@@ -68,6 +76,13 @@ resource "gridscale_server" "server_caddy" {
dst_port = 80 dst_port = 80
comment = "Allow HTTP access" comment = "Allow HTTP access"
} }
rules_v4_in {
order = 15
protocol = "tcp"
action = "accept"
dst_port = 443
comment = "Allow HTTPS access"
}
rules_v6_in { rules_v6_in {
order = 0 order = 0
protocol = "tcp" protocol = "tcp"
@@ -82,6 +97,13 @@ resource "gridscale_server" "server_caddy" {
dst_port = 80 dst_port = 80
comment = "Allow HTTPv6 access" comment = "Allow HTTPv6 access"
} }
rules_v6_in {
order = 15
protocol = "tcp"
action = "accept"
dst_port = 443
comment = "Allow HTTPSv6 access"
}
} }
network { network {
# Private network # Private network
@@ -95,8 +117,8 @@ resource "gridscale_server" "server_caddy" {
src_cidr = "192.168.121.0/27" src_cidr = "192.168.121.0/27"
} }
} }
ipv4 = gridscale_ipv4.public_ipv4.id ipv4 = gridscale_ipv4.public_ipv4_caddy.id
ipv6 = gridscale_ipv6.public_ipv6.id ipv6 = gridscale_ipv6.public_ipv6_caddy.id
timeouts { timeouts {
create = "10m" create = "10m"
} }
@@ -131,13 +153,6 @@ resource "gridscale_server" "server_monitoring" {
dst_port = 22 dst_port = 22
comment = "Allow SSH access" comment = "Allow SSH access"
} }
rules_v4_in {
order = 10
protocol = "tcp"
action = "accept"
dst_port = 80
comment = "Allow HTTP access"
}
rules_v6_in { rules_v6_in {
order = 0 order = 0
protocol = "tcp" protocol = "tcp"
@@ -145,13 +160,6 @@ resource "gridscale_server" "server_monitoring" {
dst_port = 22 dst_port = 22
comment = "Allow SSHv6 access" comment = "Allow SSHv6 access"
} }
rules_v6_in {
order = 10
protocol = "tcp"
action = "accept"
dst_port = 80
comment = "Allow HTTPv6 access"
}
} }
network { network {
# Private Network # Private Network
@@ -163,3 +171,59 @@ resource "gridscale_server" "server_monitoring" {
create = "10m" create = "10m"
} }
} }
resource "gridscale_storage" "storage_nginx" {
name = "storage_nginx"
storage_type = "storage"
capacity = 20
template {
sshkeys = [gridscale_sshkey.sshkey_richard.id]
template_uuid = data.gridscale_template.template_debian_13.id
hostname = var.nginx_hostname
}
}
resource "gridscale_server" "server_nginx" {
name = var.nginx_hostname
cores = 2
memory = 1
power = true
storage {
object_uuid = gridscale_storage.storage_nginx.id
}
network {
# Public Network
object_uuid = "5557a73b-31ee-4b1f-aa15-7789ad6ae04c"
rules_v4_in {
order = 0
protocol = "tcp"
action = "accept"
dst_port = 22
comment = "Allow SSH access"
}
rules_v6_in {
order = 0
protocol = "tcp"
action = "accept"
dst_port = 22
comment = "Allow SSHv6 access"
}
}
network {
# Private Network
object_uuid = gridscale_network.network_internal.id
rules_v4_in {
order = 10
protocol = "tcp"
action = "accept"
dst_port = 80
comment = "Allow HTTP access for Loadbalancer"
}
}
ipv4 = gridscale_ipv4.public_ipv4_nginx.id
ipv6 = gridscale_ipv6.public_ipv6_nginx.id
timeouts {
create = "10m"
}
}
+6
View File
@@ -20,3 +20,9 @@ variable "monitoring_hostname" {
description = "Monitoring hostname" description = "Monitoring hostname"
default = "monitoring01" default = "monitoring01"
} }
variable "nginx_hostname" {
type = string
description = "Nginx hostname"
default = "nginx01"
}