From fd9ee57a0b38a8040919ec67fad03698f727bff4 Mon Sep 17 00:00:00 2001 From: Thomas Hintz Date: Mon, 11 Aug 2025 06:02:37 -0700 Subject: [PATCH] Uses reserved ip address. --- cl/machine-mynode.yaml.tmpl | 2 +- main.tf | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cl/machine-mynode.yaml.tmpl b/cl/machine-mynode.yaml.tmpl index b28d86e..146d17a 100644 --- a/cl/machine-mynode.yaml.tmpl +++ b/cl/machine-mynode.yaml.tmpl @@ -15,4 +15,4 @@ storage: set -euo pipefail # This script demonstrates how templating and variable substitution works when using Terraform templates for Container Linux Configs. hostname="$(hostname)" - echo My name is ${name} and the hostname is $${hostname} and this is updated! + echo My name is ${name} and the hostname is $${hostname} and this is updated, again 4x! diff --git a/main.tf b/main.tf index dafcb15..4793845 100644 --- a/main.tf +++ b/main.tf @@ -70,6 +70,12 @@ resource "digitalocean_custom_image" "flatcar" { regions = [var.datacenter] } +resource "digitalocean_reserved_ip" "machine" { + for_each = toset(var.machines) + # droplet_id = digitalocean_droplet.machine[each.key].id + region = digitalocean_droplet.machine[each.key].region +} + resource "digitalocean_droplet" "machine" { for_each = toset(var.machines) name = "${var.cluster_name}-${each.key}" @@ -83,6 +89,12 @@ resource "digitalocean_droplet" "machine" { } } +resource "digitalocean_reserved_ip_assignment" "machine" { + for_each = toset(var.machines) + ip_address = digitalocean_reserved_ip.machine[each.key].ip_address + droplet_id = digitalocean_droplet.machine[each.key].id +} + data "ct_config" "machine-ignitions" { for_each = toset(var.machines) content = templatefile("${path.module}/cl/machine-${each.key}.yaml.tmpl", { @@ -98,3 +110,10 @@ output "ip-addresses" { "${var.cluster_name}-${key}" => digitalocean_droplet.machine[key].ipv4_address } } + +output "reserved-ip-addresses" { + value = { + for key in var.machines : + "${var.cluster_name}-${key}" => digitalocean_reserved_ip.machine[key].ip_address + } +}