Skip to content

Commit 9d76b5a

Browse files
Revert "updated the validation: check for running/stopped compute instances in the same stack compartment"
This reverts commit 654b83f.
1 parent 654b83f commit 9d76b5a

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

builds/build_cli.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ mkdir -p ${SCRIPT_DIR}/binaries/tmpbuild
6969
create_cli_bundle()
7070
{
7171
cp -Rf ${SCRIPT_DIR}/../terraform/modules ${SCRIPT_DIR}/../terraform/edition.tf ${SCRIPT_DIR}/../terraform/*.tf ${SCRIPT_DIR}/../terraform/images ${TMP_BUILD}
72+
rm ${TMP_BUILD}/modules/validators/stack_validators.tf
7273
replace_variables
7374
(cd ${TMP_BUILD}; zip -r ${SCRIPT_DIR}/binaries/wlsoci-terraform.zip *; rm -Rf ${TMP_BUILD}/*)
7475
}
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
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-
# The validation fails if any running/stopped compute instances with the display name "<service_name>-wls-0" are present in the stack compartment.
5-
6-
data "oci_core_instances" "wls_running_instances_in_stack_compartment" {
5+
# list all stacks in any state (active, deleted etc)
6+
data "oci_resourcemanager_stacks" "all_stacks_in_the_compartment" {
77
compartment_id = var.compartment_id
8-
display_name = local.instance_name_to_match
9-
state = "RUNNING"
108
}
119

12-
data "oci_core_instances" "wls_stopped_instances_in_stack_compartment" {
13-
compartment_id = var.compartment_id
14-
display_name = local.instance_name_to_match
15-
state = "STOPPED"
10+
# collect id of each stack
11+
locals {
12+
stack_list = data.oci_resourcemanager_stacks.all_stacks_in_the_compartment.stacks
13+
num_stacks = length(local.stack_list)
14+
stack_ids = [for stack in local.stack_list : { id = stack.id }]
15+
}
16+
17+
# get details of each stack from the list of stack_ids
18+
data "oci_resourcemanager_stack" "all_stacks" {
19+
count = local.num_stacks
20+
#Required
21+
stack_id = local.stack_ids[count.index].id
1622
}
1723

1824
locals {
19-
vnic_prefix = "wls"
20-
resource_name_prefix = var.service_name
21-
# The host_label value below should match with the host_label of the module wls_compute
22-
host_label = "${local.resource_name_prefix}-${local.vnic_prefix}"
23-
instance_name_to_match = "${local.host_label}-0"
24-
num_running_instances = length(data.oci_core_instances.wls_running_instances_in_stack_compartment.instances)
25-
num_stopped_instances = length(data.oci_core_instances.wls_stopped_instances_in_stack_compartment.instances)
26-
num_instances = local.num_running_instances + local.num_stopped_instances
27-
service_name_already_exists = local.num_instances > 0 ? true : false
28-
service_name_already_exists_msg = "WLSC-ERROR: Another compute instance with the name [${local.instance_name_to_match}] already exisits in the stack compartment. Try again with a different service name."
25+
stack_variables = [for stack in data.oci_resourcemanager_stack.all_stacks : { variables = stack.variables }]
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."
2931
validate_service_name_is_not_already_used = local.service_name_already_exists ? local.validators_msg_map[local.service_name_already_exists_msg] : null
3032
}

0 commit comments

Comments
 (0)