diff --git a/resource.digitalocean_droplet.this.tf b/resource.digitalocean_droplet.this.tf index 9e9e635..e2ed016 100644 --- a/resource.digitalocean_droplet.this.tf +++ b/resource.digitalocean_droplet.this.tf @@ -1,18 +1,18 @@ resource "digitalocean_droplet" "this" { - backups = true + backups = var.backups backup_policy { plan = var.backup_policy_plan weekday = var.backup_policy_weekday hour = var.backup_policy_hour } image = var.image_name - ipv6 = true + ipv6 = var.ipv6 lifecycle { ignore_changes = [ image, ] } - monitoring = true + monitoring = var.monitoring name = "${var.host_name}.${var.domain_name}" region = var.region ssh_keys = var.ssh_keys diff --git a/variable.backups.tf b/variable.backups.tf new file mode 100644 index 0000000..a1a76b1 --- /dev/null +++ b/variable.backups.tf @@ -0,0 +1,5 @@ +variable "backups" { + default = true + description = "Boolean controlling if backups are made" + type = bool +} diff --git a/variable.domain_name.tf b/variable.domain_name.tf index 67c98d8..246d5bc 100644 --- a/variable.domain_name.tf +++ b/variable.domain_name.tf @@ -1,6 +1,9 @@ variable "domain_name" { description = "The domain name to use for the droplet's DNS record" - default = "example.com" type = string -} + validation { + condition = can(regex("^[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", var.domain_name)) + error_message = "The domain name must be a valid fully-qualified domain name (e.g., example.com)." + } +} diff --git a/variable.host_name.tf b/variable.host_name.tf index 208425e..f1988c3 100644 --- a/variable.host_name.tf +++ b/variable.host_name.tf @@ -1,6 +1,9 @@ variable "host_name" { description = "The hostname for the droplet" - default = "hello-world" type = string -} + validation { + condition = can(regex("^[a-zA-Z0-9-]+$", var.host_name)) + error_message = "The host name can only contain alphanumeric characters and hyphens." + } +} diff --git a/variable.image_name.tf b/variable.image_name.tf index 50857e4..3a7f6ac 100644 --- a/variable.image_name.tf +++ b/variable.image_name.tf @@ -1,6 +1,9 @@ variable "image_name" { description = "The image ID or slug to use for the droplet" - default = "fedora-42-x64" type = string -} + validation { + condition = can(regex("^[a-zA-Z0-9-]+$", var.image_name)) + error_message = "The image name must be a valid slug or ID." + } +} diff --git a/variable.ipv6.tf b/variable.ipv6.tf new file mode 100644 index 0000000..818e0b2 --- /dev/null +++ b/variable.ipv6.tf @@ -0,0 +1,5 @@ +variable "ipv6" { + default = true + description = "Boolean controlling if IPv6 is enabled" + type = bool +} diff --git a/variable.monitoring.tf b/variable.monitoring.tf new file mode 100644 index 0000000..32942a4 --- /dev/null +++ b/variable.monitoring.tf @@ -0,0 +1,5 @@ +variable "monitoring" { + default = true + description = "Boolean controlling whether monitoring agent is installed" + type = bool +} diff --git a/variable.region.tf b/variable.region.tf index 95777ba..a1c8532 100644 --- a/variable.region.tf +++ b/variable.region.tf @@ -1,6 +1,9 @@ variable "region" { description = "The region where the droplet will be created" - default = "nyc3" type = string -} + validation { + condition = can(regex("^[a-z]{3}[0-9]$", var.region)) + error_message = "The region must be a valid DigitalOcean region format (e.g., nyc3, sfo3)." + } +} diff --git a/variable.size.tf b/variable.size.tf index 480d289..e5c79a8 100644 --- a/variable.size.tf +++ b/variable.size.tf @@ -1,6 +1,9 @@ variable "size" { description = "The slug indicating the size of the droplet" - default = "s-1vcpu-1gb" type = string -} + validation { + condition = can(regex("^[a-zA-Z0-9-]+$", var.size)) + error_message = "The size must be a valid DigitalOcean size slug (e.g., s-1vcpu-1gb)." + } +} diff --git a/variable.tags.tf b/variable.tags.tf index 3204e71..23995f3 100644 --- a/variable.tags.tf +++ b/variable.tags.tf @@ -1,6 +1,10 @@ variable "tags" { - description = "A list of tags to apply to the droplet" default = [] + description = "A list of tags to apply to the droplet" type = list(string) -} + validation { + condition = alltrue([for t in var.tags : can(regex("^[a-zA-Z0-9-_]+$", t))]) || length(var.tags) == 0 + error_message = "Tags must only contain alphanumeric characters, hyphens, and underscores." + } +}