feat: add servers module
Signed-off-by: Lander Van den Bulcke <landervandenbulcke@gmail.com>
This commit is contained in:
parent
1fffa79b9d
commit
b9f3259f6a
7 changed files with 151 additions and 0 deletions
37
modules/server/main.tf
Normal file
37
modules/server/main.tf
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
resource "hcloud_server" "server" {
|
||||
name = var.hostname
|
||||
image = "debian-12"
|
||||
server_type = var.type
|
||||
location = var.location
|
||||
|
||||
ssh_keys = ["cardno:22_498_026"]
|
||||
|
||||
public_net {
|
||||
ipv4_enabled = true
|
||||
ipv6_enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
data "cloudflare_zone" "zone" {
|
||||
filter = {
|
||||
name = var.dns_zone
|
||||
}
|
||||
}
|
||||
|
||||
resource "cloudflare_dns_record" "a" {
|
||||
zone_id = data.cloudflare_zone.zone.id
|
||||
|
||||
name = "${var.hostname}.${var.dns_zone}"
|
||||
content = hcloud_server.server.ipv4_address
|
||||
type = "A"
|
||||
ttl = "1"
|
||||
}
|
||||
|
||||
resource "cloudflare_dns_record" "aaaa" {
|
||||
zone_id = data.cloudflare_zone.zone.id
|
||||
|
||||
name = "${var.hostname}.${var.dns_zone}"
|
||||
content = hcloud_server.server.ipv6_address
|
||||
type = "AAAA"
|
||||
ttl = "1"
|
||||
}
|
||||
7
modules/server/outputs.tf
Normal file
7
modules/server/outputs.tf
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
output "ipv4_address" {
|
||||
value = hcloud_server.server.ipv4_address
|
||||
}
|
||||
|
||||
output "ipv6_address" {
|
||||
value = hcloud_server.server.ipv6_address
|
||||
}
|
||||
12
modules/server/providers.tf
Normal file
12
modules/server/providers.tf
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
cloudflare = {
|
||||
source = "cloudflare/cloudflare"
|
||||
version = "5.0.0-rc1"
|
||||
}
|
||||
hcloud = {
|
||||
source = "opentofu/hcloud"
|
||||
version = "~> 1.49.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
22
modules/server/variables.tf
Normal file
22
modules/server/variables.tf
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
variable "hostname" {
|
||||
type = string
|
||||
description = "The hostname for the server"
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
description = "The datacenter location for the server"
|
||||
default = "nbg1"
|
||||
}
|
||||
|
||||
variable "type" {
|
||||
type = string
|
||||
description = "The server type"
|
||||
default = "cax11"
|
||||
}
|
||||
|
||||
variable "dns_zone" {
|
||||
type = string
|
||||
description = "The Cloudflare DNS zone"
|
||||
default = "escapeangle.com"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue