Best practice clean up to add more descriptions and stricter type cases on variables.

This commit is contained in:
2026-08-09 19:36:59 -05:00
parent a9b20fa9ae
commit 66d4f2b775
26 changed files with 55 additions and 38 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
data "digitalocean_project" "this" { data "digitalocean_project" "this" {
count = var.use_project > 0 ? 1 : 0 count = var.use_project ? 1 : 0
name = var.project name = var.project
} }
+1 -1
View File
@@ -1,5 +1,5 @@
data "digitalocean_vpc" "this" { data "digitalocean_vpc" "this" {
count = var.use_vpc > 0 ? 1 : 0 count = var.use_vpc ? 1 : 0
name = var.vpc_name name = var.vpc_name
} }
+2 -1
View File
@@ -1,4 +1,5 @@
output "droplet" { output "droplet" {
value = digitalocean_droplet.this description = "The created DigitalOcean droplet resource"
value = digitalocean_droplet.this
} }
+4 -4
View File
@@ -1,23 +1,23 @@
resource "digitalocean_droplet" "this" { resource "digitalocean_droplet" "this" {
backups = "true" backups = true
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 = true
lifecycle { lifecycle {
ignore_changes = [ ignore_changes = [
image, image,
] ]
} }
monitoring = "true" monitoring = true
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
size = var.size size = var.size
tags = var.tags 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
} }
@@ -1,5 +1,5 @@
resource "digitalocean_project_resources" "this" { 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 project = data.digitalocean_project.this[0].id
resources = [ resources = [
digitalocean_droplet.this.urn digitalocean_droplet.this.urn
+1 -1
View File
@@ -1,7 +1,7 @@
resource "digitalocean_record" "A" { resource "digitalocean_record" "A" {
domain = data.digitalocean_domain.this.name domain = data.digitalocean_domain.this.name
name = var.host_name name = var.host_name
ttl = "300" ttl = 300
type = "A" type = "A"
value = digitalocean_droplet.this.ipv4_address value = digitalocean_droplet.this.ipv4_address
} }
+1 -1
View File
@@ -1,7 +1,7 @@
resource "digitalocean_record" "AAAA" { resource "digitalocean_record" "AAAA" {
domain = data.digitalocean_domain.this.name domain = data.digitalocean_domain.this.name
name = var.host_name name = var.host_name
ttl = "300" ttl = 300
type = "AAAA" type = "AAAA"
value = digitalocean_droplet.this.ipv6_address value = digitalocean_droplet.this.ipv6_address
} }
+1 -1
View File
@@ -1,5 +1,5 @@
resource "digitalocean_volume" "this" { 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}" description = "Data Volume for ${var.host_name}.${var.domain_name}"
name = var.host_name name = var.host_name
region = var.region region = var.region
@@ -1,5 +1,5 @@
resource "digitalocean_volume_attachment" "this" { resource "digitalocean_volume_attachment" "this" {
count = var.use_volume > 0 ? 1 : 0 count = var.use_volume ? 1 : 0
droplet_id = digitalocean_droplet.this.id droplet_id = digitalocean_droplet.this.id
volume_id = digitalocean_volume.this[0].id volume_id = digitalocean_volume.this[0].id
} }
+1 -1
View File
@@ -2,7 +2,7 @@ terraform {
required_providers { required_providers {
digitalocean = { digitalocean = {
source = "digitalocean/digitalocean" source = "digitalocean/digitalocean"
version = ">= 2.99.0" version = ">= 2.99.1"
} }
} }
required_version = ">= 1.11.5" required_version = ">= 1.11.5"
+1
View File
@@ -1,4 +1,5 @@
variable "backup_policy_hour" { variable "backup_policy_hour" {
description = "The hour of the day for backups"
# UTC Hour : 0, 4, 8, 12, 16, 20 # UTC Hour : 0, 4, 8, 12, 16, 20
default = "0" default = "0"
type = string type = string
+1
View File
@@ -1,4 +1,5 @@
variable "backup_policy_plan" { variable "backup_policy_plan" {
description = "The backup plan (e.g., daily, weekly)"
# daily or weekly # daily or weekly
default = "weekly" default = "weekly"
type = string type = string
+1
View File
@@ -1,4 +1,5 @@
variable "backup_policy_weekday" { variable "backup_policy_weekday" {
description = "The day of the week for backups (e.g., SUN)"
# SUN, MON, TUE, WED, THU, FRI, SAT # SUN, MON, TUE, WED, THU, FRI, SAT
default = "SUN" default = "SUN"
type = string type = string
+3 -2
View File
@@ -1,5 +1,6 @@
variable "domain_name" { variable "domain_name" {
default = "example.com" description = "The domain name to use for the droplet's DNS record"
type = string default = "example.com"
type = string
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "host_name" { variable "host_name" {
default = "hello-world" description = "The hostname for the droplet"
type = string default = "hello-world"
type = string
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "image_name" { variable "image_name" {
default = "fedora-42-x64" description = "The image ID or slug to use for the droplet"
type = string default = "fedora-42-x64"
type = string
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "project" { variable "project" {
default = "default" description = "The name of the DigitalOcean project"
type = string default = "default"
type = string
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "region" { variable "region" {
default = "nyc3" description = "The region where the droplet will be created"
type = string default = "nyc3"
type = string
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "size" { variable "size" {
default = "s-1vcpu-1gb" description = "The slug indicating the size of the droplet"
type = string default = "s-1vcpu-1gb"
type = string
} }
+2 -1
View File
@@ -1,4 +1,5 @@
variable "ssh_keys" { variable "ssh_keys" {
type = list(any) description = "A list of SSH key IDs or fingerprints to add to the droplet"
type = list(string)
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "tags" { variable "tags" {
default = [] description = "A list of tags to apply to the droplet"
type = list(string) default = []
type = list(string)
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "use_project" { variable "use_project" {
default = 0 description = "Whether to assign the droplet to a DigitalOcean project"
type = number default = false
type = bool
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "use_volume" { variable "use_volume" {
default = 0 description = "Whether to create and attach a block storage volume"
type = number default = false
type = bool
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "use_vpc" { variable "use_vpc" {
default = 0 description = "Whether to put the droplet in a specific VPC"
type = number default = false
type = bool
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "volume_size" { variable "volume_size" {
default = 0 description = "The size of the block storage volume in GB"
type = number default = 0
type = number
} }
+3 -2
View File
@@ -1,5 +1,6 @@
variable "vpc_name" { variable "vpc_name" {
default = "nyc3" description = "The name of the VPC where the droplet will be created"
type = string default = "nyc3"
type = string
} }