Skip to content

Commit

Permalink
Reference castai_node_configuration from within module. (#46)
Browse files Browse the repository at this point in the history
This update provides the option to pass in the configuration GUID or the resource key for all configuration_id references. This is a backwards-compatible update that maintains the current functionality of the external self-reference of the module's castai_node_configurations output.
  • Loading branch information
jhunter1-onetrust authored Dec 14, 2023
1 parent 2d8097e commit decb9c5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals {
configuration_id_regex_pattern = "[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}"
}

resource "castai_aks_cluster" "castai_cluster" {
name = var.aks_cluster_name

Expand All @@ -9,7 +13,6 @@ resource "castai_aks_cluster" "castai_cluster" {

node_resource_group = var.node_resource_group
delete_nodes_on_disconnect = var.delete_nodes_on_disconnect

}

resource "castai_node_configuration" "this" {
Expand All @@ -32,7 +35,9 @@ resource "castai_node_configuration" "this" {

resource "castai_node_configuration_default" "this" {
cluster_id = castai_aks_cluster.castai_cluster.id
configuration_id = var.default_node_configuration
configuration_id = length(regexall(local.configuration_id_regex_pattern, var.default_node_configuration)) > 0 ? var.default_node_configuration : castai_node_configuration.this[var.default_node_configuration].id

depends_on = [ castai_node_configuration.this ]
}

resource "castai_node_template" "this" {
Expand All @@ -43,7 +48,7 @@ resource "castai_node_template" "this" {
name = try(each.value.name, each.key)
is_default = try(each.value.is_default, false)
is_enabled = try(each.value.is_enabled, null)
configuration_id = try(each.value.configuration_id, null)
configuration_id = can(each.value.configuration_id) ? length(regexall(local.configuration_id_regex_pattern, each.value.configuration_id)) > 0 ? each.value.configuration_id : castai_node_configuration.this[each.value.configuration_id].id : null
should_taint = try(each.value.should_taint, true)

custom_labels = try(each.value.custom_labels, {})
Expand Down

0 comments on commit decb9c5

Please sign in to comment.