From e621f9fa59109dfe9d72cc09c1ba60d3881b376f Mon Sep 17 00:00:00 2001 From: Marcel Richter Date: Thu, 21 Mar 2024 22:59:42 +0100 Subject: [PATCH] fix(network): fix "The "count" value depends on resource attributes that cannot be determined until apply" Refs: https://github.com/hashicorp/terraform/issues/26755 --- network.tf | 11 +++++++++-- variables.tf | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/network.tf b/network.tf index c9de6ec..fe2fc50 100644 --- a/network.tf +++ b/network.tf @@ -19,8 +19,12 @@ resource "hcloud_network_subnet" "nodes" { ip_range = local.node_ipv4_cidr } +locals { + create_floating_ip = var.enable_floating_ip && var.floating_ip == null +} + resource "hcloud_floating_ip" "control_plane_ipv4" { - count = var.enable_floating_ip ? 1 : 0 + count = local.create_floating_ip ? 1 : 0 name = "control-plane-ipv4" type = "ipv4" home_location = data.hcloud_location.this.name @@ -30,12 +34,15 @@ resource "hcloud_floating_ip" "control_plane_ipv4" { data "hcloud_floating_ip" "control_plane_ipv4" { count = var.enable_floating_ip ? 1 : 0 - id = coalesce(var.floating_ip_id, hcloud_floating_ip.control_plane_ipv4[0].id) + id = coalesce(var.floating_ip.id, local.create_floating_ip ? hcloud_floating_ip.control_plane_ipv4[0].id : null) } resource "hcloud_floating_ip_assignment" "this" { floating_ip_id = data.hcloud_floating_ip.control_plane_ipv4[0].id server_id = hcloud_server.control_planes[0].id + depends_on = [ + hcloud_server.control_planes, + ] } resource "hcloud_primary_ip" "control_plane_ipv4" { diff --git a/variables.tf b/variables.tf index cd4120f..2a57df4 100644 --- a/variables.tf +++ b/variables.tf @@ -66,12 +66,15 @@ variable "enable_floating_ip" { description = "If true, a floating IP will be created and assigned to the control plane nodes." } -variable "floating_ip_id" { - type = number +variable "floating_ip" { + type = object({ + id = number, + }) default = null description = <