From 66d4f2b775022747a3a1918e65dcb406c87bd1e8 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 9 Aug 2026 19:36:59 -0500 Subject: [PATCH] Best practice clean up to add more descriptions and stricter type cases on variables. --- data.digitalocean_project.this.tf | 2 +- data.digitalocean_vpc.this.tf | 2 +- output.droplet.tf | 3 ++- resource.digitalocean_droplet.this.tf | 8 ++++---- resource.digitalocean_project_resources.this.tf | 2 +- resource.digitalocean_record.A.tf | 2 +- resource.digitalocean_record.AAAA.tf | 2 +- resource.digitalocean_volume.this.tf | 2 +- resource.digitalocean_volume_attachment.this.tf | 2 +- terraform.tf | 2 +- variable.backup_policy_hour.tf | 1 + variable.backup_policy_plan.tf | 1 + variable.backup_policy_weekday.tf | 1 + variable.domain_name.tf | 5 +++-- variable.host_name.tf | 5 +++-- variable.image_name.tf | 5 +++-- variable.project.tf | 5 +++-- variable.region.tf | 5 +++-- variable.size.tf | 5 +++-- variable.ssh_keys.tf | 3 ++- variable.tags.tf | 5 +++-- variable.use_project.tf | 5 +++-- variable.use_volume.tf | 5 +++-- variable.use_vpc.tf | 5 +++-- variable.volume_size.tf | 5 +++-- variable.vpc_name.tf | 5 +++-- 26 files changed, 55 insertions(+), 38 deletions(-) diff --git a/data.digitalocean_project.this.tf b/data.digitalocean_project.this.tf index 5fef1e1..82bcb43 100644 --- a/data.digitalocean_project.this.tf +++ b/data.digitalocean_project.this.tf @@ -1,5 +1,5 @@ data "digitalocean_project" "this" { - count = var.use_project > 0 ? 1 : 0 + count = var.use_project ? 1 : 0 name = var.project } diff --git a/data.digitalocean_vpc.this.tf b/data.digitalocean_vpc.this.tf index 12f256b..806dfa2 100644 --- a/data.digitalocean_vpc.this.tf +++ b/data.digitalocean_vpc.this.tf @@ -1,5 +1,5 @@ data "digitalocean_vpc" "this" { - count = var.use_vpc > 0 ? 1 : 0 + count = var.use_vpc ? 1 : 0 name = var.vpc_name } diff --git a/output.droplet.tf b/output.droplet.tf index c7e3425..f5774a5 100644 --- a/output.droplet.tf +++ b/output.droplet.tf @@ -1,4 +1,5 @@ output "droplet" { - value = digitalocean_droplet.this + description = "The created DigitalOcean droplet resource" + value = digitalocean_droplet.this } diff --git a/resource.digitalocean_droplet.this.tf b/resource.digitalocean_droplet.this.tf index fc0ad3d..9e9e635 100644 --- a/resource.digitalocean_droplet.this.tf +++ b/resource.digitalocean_droplet.this.tf @@ -1,23 +1,23 @@ resource "digitalocean_droplet" "this" { - backups = "true" + backups = true backup_policy { plan = var.backup_policy_plan weekday = var.backup_policy_weekday hour = var.backup_policy_hour } image = var.image_name - ipv6 = "true" + ipv6 = true lifecycle { ignore_changes = [ image, ] } - monitoring = "true" + monitoring = true name = "${var.host_name}.${var.domain_name}" region = var.region ssh_keys = var.ssh_keys size = var.size tags = var.tags - vpc_uuid = var.use_vpc > 0 ? data.digitalocean_vpc.this[0].id : null + vpc_uuid = var.use_vpc ? data.digitalocean_vpc.this[0].id : null } diff --git a/resource.digitalocean_project_resources.this.tf b/resource.digitalocean_project_resources.this.tf index 988073a..293379d 100644 --- a/resource.digitalocean_project_resources.this.tf +++ b/resource.digitalocean_project_resources.this.tf @@ -1,5 +1,5 @@ resource "digitalocean_project_resources" "this" { - count = var.use_project > 0 ? 1 : 0 + count = var.use_project ? 1 : 0 project = data.digitalocean_project.this[0].id resources = [ digitalocean_droplet.this.urn diff --git a/resource.digitalocean_record.A.tf b/resource.digitalocean_record.A.tf index a9a3d96..8c1305a 100644 --- a/resource.digitalocean_record.A.tf +++ b/resource.digitalocean_record.A.tf @@ -1,7 +1,7 @@ resource "digitalocean_record" "A" { domain = data.digitalocean_domain.this.name name = var.host_name - ttl = "300" + ttl = 300 type = "A" value = digitalocean_droplet.this.ipv4_address } diff --git a/resource.digitalocean_record.AAAA.tf b/resource.digitalocean_record.AAAA.tf index 960a582..718a9d1 100644 --- a/resource.digitalocean_record.AAAA.tf +++ b/resource.digitalocean_record.AAAA.tf @@ -1,7 +1,7 @@ resource "digitalocean_record" "AAAA" { domain = data.digitalocean_domain.this.name name = var.host_name - ttl = "300" + ttl = 300 type = "AAAA" value = digitalocean_droplet.this.ipv6_address } diff --git a/resource.digitalocean_volume.this.tf b/resource.digitalocean_volume.this.tf index dbd1bf4..533a67c 100644 --- a/resource.digitalocean_volume.this.tf +++ b/resource.digitalocean_volume.this.tf @@ -1,5 +1,5 @@ resource "digitalocean_volume" "this" { - count = var.use_volume > 0 ? 1 : 0 + count = var.use_volume ? 1 : 0 description = "Data Volume for ${var.host_name}.${var.domain_name}" name = var.host_name region = var.region diff --git a/resource.digitalocean_volume_attachment.this.tf b/resource.digitalocean_volume_attachment.this.tf index f03037d..4364507 100644 --- a/resource.digitalocean_volume_attachment.this.tf +++ b/resource.digitalocean_volume_attachment.this.tf @@ -1,5 +1,5 @@ resource "digitalocean_volume_attachment" "this" { - count = var.use_volume > 0 ? 1 : 0 + count = var.use_volume ? 1 : 0 droplet_id = digitalocean_droplet.this.id volume_id = digitalocean_volume.this[0].id } diff --git a/terraform.tf b/terraform.tf index 3b9e417..6f89dad 100644 --- a/terraform.tf +++ b/terraform.tf @@ -2,7 +2,7 @@ terraform { required_providers { digitalocean = { source = "digitalocean/digitalocean" - version = ">= 2.99.0" + version = ">= 2.99.1" } } required_version = ">= 1.11.5" diff --git a/variable.backup_policy_hour.tf b/variable.backup_policy_hour.tf index c9d59f0..7d19421 100644 --- a/variable.backup_policy_hour.tf +++ b/variable.backup_policy_hour.tf @@ -1,4 +1,5 @@ variable "backup_policy_hour" { + description = "The hour of the day for backups" # UTC Hour : 0, 4, 8, 12, 16, 20 default = "0" type = string diff --git a/variable.backup_policy_plan.tf b/variable.backup_policy_plan.tf index 5d88f3d..ba97bca 100644 --- a/variable.backup_policy_plan.tf +++ b/variable.backup_policy_plan.tf @@ -1,4 +1,5 @@ variable "backup_policy_plan" { + description = "The backup plan (e.g., daily, weekly)" # daily or weekly default = "weekly" type = string diff --git a/variable.backup_policy_weekday.tf b/variable.backup_policy_weekday.tf index afd04ce..49819e3 100644 --- a/variable.backup_policy_weekday.tf +++ b/variable.backup_policy_weekday.tf @@ -1,4 +1,5 @@ variable "backup_policy_weekday" { + description = "The day of the week for backups (e.g., SUN)" # SUN, MON, TUE, WED, THU, FRI, SAT default = "SUN" type = string diff --git a/variable.domain_name.tf b/variable.domain_name.tf index a81f65e..67c98d8 100644 --- a/variable.domain_name.tf +++ b/variable.domain_name.tf @@ -1,5 +1,6 @@ variable "domain_name" { - default = "example.com" - type = string + description = "The domain name to use for the droplet's DNS record" + default = "example.com" + type = string } diff --git a/variable.host_name.tf b/variable.host_name.tf index dfb11f2..208425e 100644 --- a/variable.host_name.tf +++ b/variable.host_name.tf @@ -1,5 +1,6 @@ variable "host_name" { - default = "hello-world" - type = string + description = "The hostname for the droplet" + default = "hello-world" + type = string } diff --git a/variable.image_name.tf b/variable.image_name.tf index e37e997..50857e4 100644 --- a/variable.image_name.tf +++ b/variable.image_name.tf @@ -1,5 +1,6 @@ variable "image_name" { - default = "fedora-42-x64" - type = string + description = "The image ID or slug to use for the droplet" + default = "fedora-42-x64" + type = string } diff --git a/variable.project.tf b/variable.project.tf index 9261018..1c0b144 100644 --- a/variable.project.tf +++ b/variable.project.tf @@ -1,5 +1,6 @@ variable "project" { - default = "default" - type = string + description = "The name of the DigitalOcean project" + default = "default" + type = string } diff --git a/variable.region.tf b/variable.region.tf index 8f292b2..95777ba 100644 --- a/variable.region.tf +++ b/variable.region.tf @@ -1,5 +1,6 @@ variable "region" { - default = "nyc3" - type = string + description = "The region where the droplet will be created" + default = "nyc3" + type = string } diff --git a/variable.size.tf b/variable.size.tf index 99df51d..480d289 100644 --- a/variable.size.tf +++ b/variable.size.tf @@ -1,5 +1,6 @@ variable "size" { - default = "s-1vcpu-1gb" - type = string + description = "The slug indicating the size of the droplet" + default = "s-1vcpu-1gb" + type = string } diff --git a/variable.ssh_keys.tf b/variable.ssh_keys.tf index 885c071..2e98924 100644 --- a/variable.ssh_keys.tf +++ b/variable.ssh_keys.tf @@ -1,4 +1,5 @@ variable "ssh_keys" { - type = list(any) + description = "A list of SSH key IDs or fingerprints to add to the droplet" + type = list(string) } diff --git a/variable.tags.tf b/variable.tags.tf index 6e55167..3204e71 100644 --- a/variable.tags.tf +++ b/variable.tags.tf @@ -1,5 +1,6 @@ variable "tags" { - default = [] - type = list(string) + description = "A list of tags to apply to the droplet" + default = [] + type = list(string) } diff --git a/variable.use_project.tf b/variable.use_project.tf index 18355d7..72946d6 100644 --- a/variable.use_project.tf +++ b/variable.use_project.tf @@ -1,5 +1,6 @@ variable "use_project" { - default = 0 - type = number + description = "Whether to assign the droplet to a DigitalOcean project" + default = false + type = bool } diff --git a/variable.use_volume.tf b/variable.use_volume.tf index 8bb177a..45c3525 100644 --- a/variable.use_volume.tf +++ b/variable.use_volume.tf @@ -1,5 +1,6 @@ variable "use_volume" { - default = 0 - type = number + description = "Whether to create and attach a block storage volume" + default = false + type = bool } diff --git a/variable.use_vpc.tf b/variable.use_vpc.tf index 8746414..8dc669c 100644 --- a/variable.use_vpc.tf +++ b/variable.use_vpc.tf @@ -1,5 +1,6 @@ variable "use_vpc" { - default = 0 - type = number + description = "Whether to put the droplet in a specific VPC" + default = false + type = bool } diff --git a/variable.volume_size.tf b/variable.volume_size.tf index 533f809..93f37d0 100644 --- a/variable.volume_size.tf +++ b/variable.volume_size.tf @@ -1,5 +1,6 @@ variable "volume_size" { - default = 0 - type = number + description = "The size of the block storage volume in GB" + default = 0 + type = number } diff --git a/variable.vpc_name.tf b/variable.vpc_name.tf index 3cc57a0..591109e 100644 --- a/variable.vpc_name.tf +++ b/variable.vpc_name.tf @@ -1,5 +1,6 @@ variable "vpc_name" { - default = "nyc3" - type = string + description = "The name of the VPC where the droplet will be created" + default = "nyc3" + type = string }