Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc81c141aa | ||
|
|
ea42bea0a2 | ||
|
|
dc1a6a8556 | ||
|
|
68290e3e89 |
No files matched your search
@@ -16,6 +16,6 @@ resource "cloudflare_dns_record" "this" {
|
|||||||
name = var.record_name
|
name = var.record_name
|
||||||
type = var.record_type
|
type = var.record_type
|
||||||
content = var.record_value
|
content = var.record_value
|
||||||
proxied = var.proxied
|
proxied = var.cloudflare_proxied
|
||||||
ttl = var.proxied ? 1 : var.ttl
|
ttl = var.cloudflare_proxied ? 1 : var.record_ttl
|
||||||
}
|
}
|
||||||
@@ -18,18 +18,18 @@ variable "record_value" {
|
|||||||
description = "Record content (IP address, target hostname, text)"
|
description = "Record content (IP address, target hostname, text)"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "proxied" {
|
variable "cloudflare_proxied" {
|
||||||
type = bool
|
type = bool
|
||||||
description = "Route through the Cloudflare proxy (orange cloud)"
|
description = "Route through the Cloudflare proxy (orange cloud)"
|
||||||
default = true
|
default = true
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "ttl" {
|
variable "record_ttl" {
|
||||||
type = number
|
type = number
|
||||||
description = "TTL in seconds (ignored when proxied)"
|
description = "TTL in seconds (ignored when proxied)"
|
||||||
default = 3600
|
default = 3600
|
||||||
validation {
|
validation {
|
||||||
condition = var.ttl >= 60 && var.ttl <= 86400
|
condition = var.record_ttl >= 60 && var.record_ttl <= 86400
|
||||||
error_message = "ttl must be between 60 and 86400 seconds"
|
error_message = "ttl must be between 60 and 86400 seconds"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">= 1.0.0"
|
||||||
|
required_providers {
|
||||||
|
hcloud = { source = "hetznercloud/hcloud", version = "~> 1.68.0" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
# single naming scheme - propagates everywhere
|
||||||
|
ssh_key_name = "${var.project_name}-key"
|
||||||
|
firewall_name = "${var.project_name}-fw"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "hcloud_ssh_key" "this" {
|
||||||
|
name = local.ssh_key_name
|
||||||
|
public_key = var.ssh_public_key
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "hcloud_firewall" "this" {
|
||||||
|
name = local.firewall_name
|
||||||
|
|
||||||
|
dynamic "rule" {
|
||||||
|
for_each = var.firewall_rules
|
||||||
|
content {
|
||||||
|
direction = rule.value.direction
|
||||||
|
protocol = rule.value.protocol
|
||||||
|
port = rule.value.port
|
||||||
|
source_ips = rule.value.source_ips
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "hcloud_server" "this" {
|
||||||
|
name = var.project_name
|
||||||
|
image = var.hcloud_image
|
||||||
|
server_type = var.hcloud_server_type
|
||||||
|
location = var.hcloud_location
|
||||||
|
user_data = var.init_user_data
|
||||||
|
firewall_ids = [hcloud_firewall.this.id]
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
output "ipv4_address" {
|
||||||
|
description = "Primary public IPv4 address of the host"
|
||||||
|
value = hcloud_server.this.ipv4_address
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ipv6_address" {
|
||||||
|
description = "Primary public IPv6 address of the host"
|
||||||
|
value = hcloud_server.this.ipv6_address
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
variable "project_name" {
|
||||||
|
type = string
|
||||||
|
description = "Project / host name"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_public_key" {
|
||||||
|
type = string
|
||||||
|
description = "Public SSH key to manage the host"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "hcloud_server_type" {
|
||||||
|
type = string
|
||||||
|
description = "Hetzner server type (e.g. cx22)"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "hcloud_image" {
|
||||||
|
type = string
|
||||||
|
description = "OS image to boot (e.g. debian-13)"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "hcloud_location" {
|
||||||
|
type = string
|
||||||
|
description = "Hetzner location (fsn1, nbg1, hel1, ash1)"
|
||||||
|
validation {
|
||||||
|
condition = contains(["fsn1", "nbg1", "hel1", "ash1"], var.hcloud_location)
|
||||||
|
error_message = "location must be one of fsn1, nbg1, hel1, ash1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "init_user_data" {
|
||||||
|
type = string
|
||||||
|
description = "Pre-rendered cloud-init user data (optional)"
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "firewall_rules" {
|
||||||
|
type = list(object({
|
||||||
|
direction = string
|
||||||
|
protocol = string
|
||||||
|
port = string
|
||||||
|
source_ips = list(string)
|
||||||
|
}))
|
||||||
|
description = "Firewall rules applied to the host"
|
||||||
|
default = []
|
||||||
|
}
|
||||||
Reference in new issue
Block a user