Skip to content

Commit aa23c6c

Browse files
JCS-14427: Add suggested actions for 409-PolicyAlreadyExists error in ORM job log (#254)
Setting up validation to raise an error if the dynamic group policy already exists with the same name as that of any service name of stack. ![policy_error](https://github.com/oracle-quickstart/oci-weblogic-server/assets/146092663/99e4c142-bf81-46f7-be24-e5624bbffd50)
1 parent 2cb6db7 commit aa23c6c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

terraform/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ module "validators" {
464464
provisioned_node_count = length(data.oci_core_instances.provisioned_instances.instances.*.display_name)
465465
use_marketplace_image = var.use_marketplace_image
466466
wls_edition = var.wls_edition
467+
tenancy_id = var.tenancy_ocid
467468
}
468469

469470
module "fss" {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2024 Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
data "oci_identity_policies" "existing_policies" {
5+
compartment_id = var.tenancy_id
6+
}
7+
8+
locals {
9+
policy_name = var.create_policies ? "${var.service_name}-oci-policy" : ""
10+
existing_policy_names = var.create_policies ? [for policy in data.oci_identity_policies.existing_policies.policies : policy.name] : []
11+
policy_already_exists = var.create_policies ? contains(local.existing_policy_names, local.policy_name) : false
12+
policy_already_exists_msg = "WLSC-ERROR: Policy with name ${local.policy_name} already exists. Suggested Actions: It appears that another policy with the same name already exists. This could be because you have previously provisioned a stack with the same resource name prefix. If you no longer need the previous stack, please destroy and delete it so that all the resources are cleaned up or else you can provision again with a different resource name prefix. If you have already deleted the stack, delete the policy ${local.policy_name}."
13+
validate_policy_name_is_not_already_used = var.create_policies && local.policy_already_exists ? local.validators_msg_map[local.policy_already_exists_msg] : null
14+
}

terraform/modules/validators/variables.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023, Oracle and/or its affiliates.
1+
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
variable "compartment_id" {
@@ -533,3 +533,12 @@ variable "tf_script_version" {
533533
type = string
534534
description = "The version of the provisioning scripts located in the OCI image used to create the WebLogic compute instances"
535535
}
536+
537+
variable "tenancy_id" {
538+
type = string
539+
description = "The OCID of the tenancy where the dynamic group and policy will be created"
540+
validation {
541+
condition = length(regexall("^ocid1.tenancy.*$", var.tenancy_id)) > 0
542+
error_message = "WLSC-ERROR: The value for tenancy_id should start with \"ocid1.tenancy.\"."
543+
}
544+
}

0 commit comments

Comments
 (0)