From b5039e2bc1705c3b58448dde6b8b164288d02947 Mon Sep 17 00:00:00 2001 From: jodhi Date: Thu, 24 Feb 2022 23:57:36 +0700 Subject: [PATCH] fix dynamic private ip --- locals.tf | 1 - modules/host/main.tf | 10 +++++----- modules/host/out.tf | 2 +- modules/host/variables.tf | 7 ------- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/locals.tf b/locals.tf index 7932296..3c78ad0 100644 --- a/locals.tf +++ b/locals.tf @@ -35,7 +35,6 @@ locals { for nodepool_name, nodepool_obj in var.agent_nodepools : { for index in range(lookup(nodepool_obj, "count", var.agents_num)) : format("%s-%s", nodepool_name, index) => { - index : index, # just for the compatibility with previous structure server_type : nodepool_obj.server_type } } diff --git a/modules/host/main.tf b/modules/host/main.tf index 56e794e..b8b8dd9 100644 --- a/modules/host/main.tf +++ b/modules/host/main.tf @@ -12,11 +12,6 @@ resource "hcloud_server" "server" { labels = var.labels - network { - network_id = var.network_id - ip = try(var.ip, null) - } - connection { user = "root" private_key = local.ssh_private_key @@ -68,3 +63,8 @@ resource "hcloud_server" "server" { ] } } + +resource "hcloud_server_network" "server" { + server_id = hcloud_server.server.id + network_id = var.network_id +} diff --git a/modules/host/out.tf b/modules/host/out.tf index d2997ba..1c373c1 100644 --- a/modules/host/out.tf +++ b/modules/host/out.tf @@ -3,7 +3,7 @@ output "ipv4_address" { } output "private_ipv4_address" { - value = var.ip + value = hcloud_server_network.server.ip } output "name" { diff --git a/modules/host/variables.tf b/modules/host/variables.tf index 9c328b1..77a8176 100644 --- a/modules/host/variables.tf +++ b/modules/host/variables.tf @@ -59,13 +59,6 @@ variable "network_id" { type = number } -variable "ip" { - default = null - description = "The IP" - type = string - nullable = true -} - variable "server_type" { description = "The server type" type = string