Version bump, Style guide, dns records updates optional, and input validation
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
data "linode_domain" "this" {
|
data "linode_domain" "this" {
|
||||||
|
count = var.create_dns_record ? 1 : 0
|
||||||
domain = var.domain_name
|
domain = var.domain_name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
output "domain_records" {
|
||||||
|
description = "The DNS records created for the instance, if create_dns_record is true."
|
||||||
|
value = {
|
||||||
|
ipv4 = try(linode_domain_record.this_ipv4[0], null)
|
||||||
|
ipv6 = try(linode_domain_record.this_ipv6[0], null)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
output "fqdn" {
|
||||||
|
description = "The fully qualified domain name of the Linode instance."
|
||||||
|
value = "${var.host_name}.${var.domain_name}"
|
||||||
|
}
|
||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
output "instance" {
|
output "instance" {
|
||||||
value = linode_instance.this
|
description = "The entire linode_instance.this resource."
|
||||||
|
value = linode_instance.this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
resource "linode_domain_record" "this_ipv4" {
|
resource "linode_domain_record" "this_ipv4" {
|
||||||
domain_id = data.linode_domain.this.id
|
count = var.create_dns_record ? 1 : 0
|
||||||
|
domain_id = data.linode_domain.this[0].id
|
||||||
name = var.host_name
|
name = var.host_name
|
||||||
record_type = "A"
|
record_type = "A"
|
||||||
target = linode_instance.this.ip_address
|
target = linode_instance.this.ip_address
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
resource "linode_domain_record" "this_ipv6" {
|
resource "linode_domain_record" "this_ipv6" {
|
||||||
domain_id = data.linode_domain.this.id
|
count = var.create_dns_record ? 1 : 0
|
||||||
|
domain_id = data.linode_domain.this[0].id
|
||||||
name = var.host_name
|
name = var.host_name
|
||||||
record_type = "AAAA"
|
record_type = "AAAA"
|
||||||
target = element(split("/", linode_instance.this.ipv6), 0)
|
target = element(split("/", linode_instance.this.ipv6), 0)
|
||||||
|
|||||||
@@ -2,11 +2,17 @@ resource "linode_instance" "this" {
|
|||||||
authorized_keys = var.authorized_keys
|
authorized_keys = var.authorized_keys
|
||||||
backups_enabled = var.backups_enabled
|
backups_enabled = var.backups_enabled
|
||||||
booted = var.booted
|
booted = var.booted
|
||||||
label = "${var.host_name}.${var.domain_name}"
|
|
||||||
image = var.image
|
image = var.image
|
||||||
|
label = "${var.host_name}.${var.domain_name}"
|
||||||
private_ip = var.private_ip
|
private_ip = var.private_ip
|
||||||
|
region = var.region
|
||||||
tags = var.tags
|
tags = var.tags
|
||||||
type = var.type
|
type = var.type
|
||||||
region = var.region
|
|
||||||
watchdog_enabled = var.watchdog_enabled
|
watchdog_enabled = var.watchdog_enabled
|
||||||
|
|
||||||
|
lifecycle {
|
||||||
|
ignore_changes = [
|
||||||
|
image,
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
linode = {
|
linode = {
|
||||||
source = "linode/linode"
|
source = "linode/linode"
|
||||||
version = ">= 4.2.0"
|
version = ">= 4.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
required_version = ">= 1.11.5"
|
required_version = ">= 1.11.5"
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
variable "authorized_keys" {
|
variable "authorized_keys" {
|
||||||
default = []
|
default = []
|
||||||
type = list(string)
|
description = "A list of SSH public keys to deploy for the root user on the newly created Linode instance."
|
||||||
|
type = list(string)
|
||||||
|
|
||||||
|
validation {
|
||||||
|
condition = alltrue([for key in var.authorized_keys : can(regex("^(ssh-rsa|ssh-ed25519|ecdsa-sha2-nistp256|ssh-dss)", key))]) || length(var.authorized_keys) == 0
|
||||||
|
error_message = "All authorized keys must be valid SSH public keys starting with ssh-rsa, ssh-ed25519, ecdsa-sha2-nistp256, or ssh-dss."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
variable "backups_enabled" {
|
variable "backups_enabled" {
|
||||||
default = true
|
default = true
|
||||||
type = bool
|
description = "If this field is set to true, the created Linode will automatically be enrolled in the Linode Backup service."
|
||||||
|
type = bool
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -1,4 +1,5 @@
|
|||||||
variable "booted" {
|
variable "booted" {
|
||||||
default = true
|
default = true
|
||||||
type = bool
|
description = "If true, then the instance is kept or converted into a running state."
|
||||||
|
type = bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
variable "create_dns_record" {
|
||||||
|
default = true
|
||||||
|
description = "If true, the module will look up the domain_name and create A and AAAA records for the instance."
|
||||||
|
type = bool
|
||||||
|
}
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
variable "domain_name" {
|
variable "domain_name" {
|
||||||
default = "example.com"
|
default = "example.com"
|
||||||
type = string
|
description = "The domain name for the Linode instance and domain records."
|
||||||
|
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,4 +1,10 @@
|
|||||||
variable "host_name" {
|
variable "host_name" {
|
||||||
default = "hello-world"
|
default = "hello-world"
|
||||||
type = string
|
description = "The host name for the Linode instance."
|
||||||
|
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."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -1,4 +1,10 @@
|
|||||||
variable "image" {
|
variable "image" {
|
||||||
default = "linode/fedora38"
|
default = "linode/fedora44"
|
||||||
type = string
|
description = "An Image ID to deploy the Disk from."
|
||||||
|
type = string
|
||||||
|
|
||||||
|
validation {
|
||||||
|
condition = can(regex("^[a-zA-Z0-9-]+/[a-zA-Z0-9.-]+$", var.image))
|
||||||
|
error_message = "The image must be a valid Linode image ID (e.g., linode/fedora44)."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
variable "private_ip" {
|
variable "private_ip" {
|
||||||
default = true
|
default = true
|
||||||
type = bool
|
description = "If true, the created Linode will have private networking enabled."
|
||||||
|
type = bool
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -1,4 +1,10 @@
|
|||||||
variable "region" {
|
variable "region" {
|
||||||
default = "us-central"
|
default = "us-central"
|
||||||
type = string
|
description = "The region where the Linode will be located."
|
||||||
|
type = string
|
||||||
|
|
||||||
|
validation {
|
||||||
|
condition = can(regex("^[a-z]{2}-[a-z]+(-[a-z]+)?$", var.region))
|
||||||
|
error_message = "The region must be a valid Linode region format (e.g., us-central, ap-south)."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -1,4 +1,10 @@
|
|||||||
variable "tags" {
|
variable "tags" {
|
||||||
default = []
|
default = []
|
||||||
type = list(string)
|
description = "A list of tags applied to this object."
|
||||||
|
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."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -1,4 +1,10 @@
|
|||||||
variable "type" {
|
variable "type" {
|
||||||
default = "g6-nanode-1"
|
default = "g6-nanode-1"
|
||||||
type = string
|
description = "The Linode type defines the pricing, CPU, disk, and RAM specs of the instance."
|
||||||
|
type = string
|
||||||
|
|
||||||
|
validation {
|
||||||
|
condition = can(regex("^g[0-9]+-[a-zA-Z0-9-]+$", var.type))
|
||||||
|
error_message = "The type must be a valid Linode instance type (e.g., g6-nanode-1, g6-standard-2)."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
variable "watchdog_enabled" {
|
variable "watchdog_enabled" {
|
||||||
default = true
|
default = true
|
||||||
type = bool
|
description = "The watchdog, named Lassie, is a Shutdown Watchdog that monitors your Linode and will reboot it if it powers off unexpectedly."
|
||||||
|
type = bool
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user