Expose a few more configurable items and add input validators
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
resource "digitalocean_droplet" "this" {
|
resource "digitalocean_droplet" "this" {
|
||||||
backups = true
|
backups = var.backups
|
||||||
backup_policy {
|
backup_policy {
|
||||||
plan = var.backup_policy_plan
|
plan = var.backup_policy_plan
|
||||||
weekday = var.backup_policy_weekday
|
weekday = var.backup_policy_weekday
|
||||||
hour = var.backup_policy_hour
|
hour = var.backup_policy_hour
|
||||||
}
|
}
|
||||||
image = var.image_name
|
image = var.image_name
|
||||||
ipv6 = true
|
ipv6 = var.ipv6
|
||||||
lifecycle {
|
lifecycle {
|
||||||
ignore_changes = [
|
ignore_changes = [
|
||||||
image,
|
image,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
monitoring = true
|
monitoring = var.monitoring
|
||||||
name = "${var.host_name}.${var.domain_name}"
|
name = "${var.host_name}.${var.domain_name}"
|
||||||
region = var.region
|
region = var.region
|
||||||
ssh_keys = var.ssh_keys
|
ssh_keys = var.ssh_keys
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
variable "backups" {
|
||||||
|
default = true
|
||||||
|
description = "Boolean controlling if backups are made"
|
||||||
|
type = bool
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
variable "domain_name" {
|
variable "domain_name" {
|
||||||
description = "The domain name to use for the droplet's DNS record"
|
description = "The domain name to use for the droplet's DNS record"
|
||||||
default = "example.com"
|
|
||||||
type = string
|
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)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
variable "host_name" {
|
variable "host_name" {
|
||||||
description = "The hostname for the droplet"
|
description = "The hostname for the droplet"
|
||||||
default = "hello-world"
|
|
||||||
type = string
|
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."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
variable "image_name" {
|
variable "image_name" {
|
||||||
description = "The image ID or slug to use for the droplet"
|
description = "The image ID or slug to use for the droplet"
|
||||||
default = "fedora-42-x64"
|
|
||||||
type = string
|
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."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
variable "ipv6" {
|
||||||
|
default = true
|
||||||
|
description = "Boolean controlling if IPv6 is enabled"
|
||||||
|
type = bool
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
variable "monitoring" {
|
||||||
|
default = true
|
||||||
|
description = "Boolean controlling whether monitoring agent is installed"
|
||||||
|
type = bool
|
||||||
|
}
|
||||||
+5
-2
@@ -1,6 +1,9 @@
|
|||||||
variable "region" {
|
variable "region" {
|
||||||
description = "The region where the droplet will be created"
|
description = "The region where the droplet will be created"
|
||||||
default = "nyc3"
|
|
||||||
type = string
|
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)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+5
-2
@@ -1,6 +1,9 @@
|
|||||||
variable "size" {
|
variable "size" {
|
||||||
description = "The slug indicating the size of the droplet"
|
description = "The slug indicating the size of the droplet"
|
||||||
default = "s-1vcpu-1gb"
|
|
||||||
type = string
|
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)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+6
-2
@@ -1,6 +1,10 @@
|
|||||||
variable "tags" {
|
variable "tags" {
|
||||||
description = "A list of tags to apply to the droplet"
|
|
||||||
default = []
|
default = []
|
||||||
|
description = "A list of tags to apply to the droplet"
|
||||||
type = list(string)
|
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."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user