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" {
count = var.use_project > 0 ? 1 : 0
count = var.use_project ? 1 : 0
name = var.project
}
+1 -1
View File
@@ -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
}
+2 -1
View File
@@ -1,4 +1,5 @@
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" {
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
}
@@ -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
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
@@ -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
}
+1 -1
View File
@@ -2,7 +2,7 @@ terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.99.0"
version = ">= 2.99.1"
}
}
required_version = ">= 1.11.5"
+1
View File
@@ -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
+1
View File
@@ -1,4 +1,5 @@
variable "backup_policy_plan" {
description = "The backup plan (e.g., daily, weekly)"
# daily or weekly
default = "weekly"
type = string
+1
View File
@@ -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
+3 -2
View File
@@ -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
}
+3 -2
View File
@@ -1,5 +1,6 @@
variable "host_name" {
default = "hello-world"
type = string
description = "The hostname for the droplet"
default = "hello-world"
type = string
}
+3 -2
View File
@@ -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
}
+3 -2
View File
@@ -1,5 +1,6 @@
variable "project" {
default = "default"
type = string
description = "The name of the DigitalOcean project"
default = "default"
type = string
}
+3 -2
View File
@@ -1,5 +1,6 @@
variable "region" {
default = "nyc3"
type = string
description = "The region where the droplet will be created"
default = "nyc3"
type = string
}
+3 -2
View File
@@ -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
}
+2 -1
View File
@@ -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)
}
+3 -2
View File
@@ -1,5 +1,6 @@
variable "tags" {
default = []
type = list(string)
description = "A list of tags to apply to the droplet"
default = []
type = list(string)
}
+3 -2
View File
@@ -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
}
+3 -2
View File
@@ -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
}
+3 -2
View File
@@ -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
}
+3 -2
View File
@@ -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
}
+3 -2
View File
@@ -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
}