From 805f30f43ca5a29aa985d2aff8dcc87f56a9584c Mon Sep 17 00:00:00 2001 From: Vladyslav Klokun Date: Tue, 20 Aug 2024 14:04:59 +0300 Subject: [PATCH] fix: use node affinity objects instead of their keys when mapping Previously, when a user specified node affinities, for every provided node affinity we would try to map every _key_ to an "affinity" block. This produced invalid Terraform resources, because the values of the "key", "name" and "operator" keys on their own are not enough to create a valid "affinity" block. This commit uses entire affinity objects and maps them to appropriate Terraform representations, fixing the problem. --- main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 96cb690..f1d352d 100644 --- a/main.tf +++ b/main.tf @@ -125,12 +125,12 @@ resource "castai_node_template" "this" { instance_types = try(dedicated_node_affinity.value.instance_types, []) dynamic "affinity" { - for_each = try(dedicated_node_affinity.value.affinity, {}) + for_each = flatten([lookup(dedicated_node_affinity.value, "affinity", [])]) content { - key = try(affinity.key, null) - operator = try(affinity.operator, null) - values = try(affinity.values, []) + key = try(affinity.value.key, null) + operator = try(affinity.value.operator, null) + values = try(affinity.value.values, []) } } }