Skip to content

Commit a9b473b

Browse files
allow one service_name entry for the name of current stack
1 parent 6f6c12c commit a9b473b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# Copyright (c) 2023, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
# This validation is applicable only for resource manager stacks. Not applicable for terraform CLI mode.
34

4-
# list all stacks in all states (active, deleted etc)
5+
# list all stacks in any state (active, deleted etc)
56
data "oci_resourcemanager_stacks" "all_stacks_in_the_compartment" {
67
compartment_id = var.compartment_id
78
}
89

10+
# collect id of each stack
911
locals {
1012
stack_list = data.oci_resourcemanager_stacks.all_stacks_in_the_compartment.stacks
1113
num_stacks = length(local.stack_list)
1214
stack_ids = [for stack in local.stack_list : { id = stack.id }]
1315
}
1416

15-
# get details of each stack
17+
# get details of each stack from the list of stack_ids
1618
data "oci_resourcemanager_stack" "all_stacks" {
1719
count = local.num_stacks
1820
#Required
@@ -21,8 +23,10 @@ data "oci_resourcemanager_stack" "all_stacks" {
2123

2224
locals {
2325
stack_variables = [for stack in data.oci_resourcemanager_stack.all_stacks : { variables = stack.variables }]
24-
service_names_used_by_existing_stacks = [for stack_variables in local.stack_variables : lookup(stack_variables.variables, "service_name", "?service_name_attribute_not_found?")]
25-
service_name_already_exists = contains(local.service_names_used_by_existing_stacks, var.service_name) ? true : false
26-
service_name_already_exists_msg = "WLSC-ERROR: The stack with the service_name [${var.service_name}] already exisits in the stack compartment. Try again with a different service name."
26+
service_names_used_by_existing_stacks = [for stack_variables in local.stack_variables : lookup(stack_variables.variables, "service_name", "?_not_found_?")]
27+
duplicate_service_names_list = [for service_name in local.service_names_used_by_existing_stacks : service_name if service_name == var.service_name]
28+
# There will be always one entry for the name of the current stack. Set duplicate to true if there are more than one entries.
29+
service_name_already_exists = length(local.duplicate_service_names_list) > 1 ? true : false
30+
service_name_already_exists_msg = "WLSC-ERROR: Another stack with the service_name [${var.service_name}] already exisits in the stack compartment. Try again with a different service name."
2731
validate_service_name_is_not_already_used = local.service_name_already_exists ? local.validators_msg_map[local.service_name_already_exists_msg] : null
2832
}

0 commit comments

Comments
 (0)