Skip to content

Commit c8dbcbc

Browse files
Topic sk jcs more fss fixes (#115)
* more fss fixes for AD specific subnet. * Revert "more fss fixes for AD specific subnet." This reverts commit 2f5e48d. * More fixes for fss/MT. Remove subnet id for existing mt and existing fss Remove subnet cidr for existing mt and existing fss Fix AD ui screen. * terraform fmt 14c schema.yaml fix. * Fix AD issue with FSS * JCS-13511 - Improvements to existing FSS use case * tf format. * Fixed issue with new FSS * Fixed issue with new FSS * Topic sk jcs mt vcn check (#112) * Check if the mount target is is from the same vcn as network vcn. * terraform fmt. * incorporated Roberto's comments. * terraform fmt. * FIx the datasources. * tf fmt. * Fix the non fss issue. * terraform fmt. Co-authored-by: Abhijit Paranjpe <[email protected]>
1 parent ef88ded commit c8dbcbc

File tree

16 files changed

+133
-92
lines changed

16 files changed

+133
-92
lines changed

terraform/data_sources.tf

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,22 @@ data "oci_file_storage_mount_targets" "mount_targets" {
113113
#Required
114114
availability_domain = local.fss_availability_domain
115115
compartment_id = var.mount_target_compartment_id
116-
117-
id = var.mount_target_id
116+
id = var.mount_target_id
118117
}
119118

120-
data "oci_file_storage_exports" "export" {
121-
count = var.existing_fss_id != "" ? 1 : 0
122-
id = var.existing_export_path_id
123-
}
124119

125-
data "oci_file_storage_mount_targets" "mount_target_by_export_set" {
120+
data "oci_file_storage_mount_targets" "existing_mount_target" {
126121
count = var.existing_fss_id != "" ? 1 : 0
127122
#Required
128123
availability_domain = local.fss_availability_domain
129-
compartment_id = var.fss_compartment_id
130-
export_set_id = data.oci_file_storage_exports.export[0].export_set_id
124+
compartment_id = var.mount_target_compartment_id
125+
id = var.mount_target_id
131126
}
132127

133128
data "oci_core_private_ip" "mount_target_private_ips" {
134129
count = var.existing_fss_id != "" ? 1 : 0
135130
#Required
136-
private_ip_id = data.oci_file_storage_mount_targets.mount_target_by_export_set[0].mount_targets[0].private_ip_ids[0]
131+
private_ip_id = data.oci_file_storage_mount_targets.existing_mount_target[0].mount_targets[0].private_ip_ids[0]
137132
}
138133

139134
data "oci_apm_apm_domain" "apm_domain" {
@@ -149,6 +144,20 @@ data "oci_core_vcn" "wls_vcn" {
149144
vcn_id = var.wls_existing_vcn_id
150145
}
151146

147+
data "oci_core_subnet" "mount_target_existing_subnet" {
148+
count = var.mount_target_id == "" ? 0 : 1
149+
150+
#Required
151+
subnet_id = data.oci_file_storage_mount_targets.mount_targets[0].mount_targets[0].subnet_id
152+
}
153+
154+
data "oci_core_subnet" "mount_target_existing_subnet_by_fss" {
155+
count = var.existing_fss_id == "" ? 0 : 1
156+
157+
#Required
158+
subnet_id = data.oci_file_storage_mount_targets.existing_mount_target[0].mount_targets[0].subnet_id
159+
}
160+
152161
data "oci_objectstorage_namespace" "object_namespace" {
153162

154163
#Optional

terraform/fss_variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ variable "existing_fss_id" {
2525
default = ""
2626
}
2727

28-
variable "existing_export_path_id" {
29-
type = string
30-
description = "The OCID of the existing export path"
31-
default = ""
32-
}
33-
3428
variable "fss_compartment_id" {
3529
type = string
3630
description = "The OCID of the compartment where the file system exists"

terraform/locals.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
locals {
55
service_name_prefix = replace(var.service_name, "/[^a-zA-Z0-9]/", "")
66

7-
home_region = lookup(data.oci_identity_regions.home_region.regions[0], "name")
8-
ad_names = compact(data.template_file.ad_names.*.rendered)
9-
export_path = format("/%s", var.service_name)
10-
vm_instance_image_id = var.terms_and_conditions ? var.ucm_instance_image_id : var.instance_image_id
11-
7+
home_region = lookup(data.oci_identity_regions.home_region.regions[0], "name")
8+
ad_names = compact(data.template_file.ad_names.*.rendered)
9+
export_path = format("/%s", var.service_name)
10+
vm_instance_image_id = var.terms_and_conditions ? var.ucm_instance_image_id : var.instance_image_id
11+
add_existing_mount_target = (var.add_existing_mount_target || var.add_existing_fss)
1212
bastion_availability_domain = var.bastion_subnet_id != "" ? (local.use_regional_subnet ? var.wls_availability_domain_name != "" ? var.wls_availability_domain_name : local.ad_names[0] : data.oci_core_subnet.bastion_subnet[0].availability_domain) : (local.use_regional_subnet ? var.wls_availability_domain_name != "" ? var.wls_availability_domain_name : local.ad_names[0] : var.wls_availability_domain_name)
1313
wls_availability_domain = local.use_regional_subnet ? (var.wls_availability_domain_name == "" ? local.ad_names[0] : var.wls_availability_domain_name) : (var.wls_subnet_id == "" ? var.wls_availability_domain_name : data.oci_core_subnet.wls_subnet[0].availability_domain)
1414
lb_availability_domain_name1 = var.lb_subnet_1_id != "" ? (local.use_regional_subnet ? "" : data.oci_core_subnet.lb_subnet_1_id[0].availability_domain) : ""
1515
lb_availability_domain_name2 = var.lb_subnet_2_id != "" ? (local.use_regional_subnet ? "" : data.oci_core_subnet.lb_subnet_2_id[0].availability_domain) : ""
16-
fss_availability_domain = var.add_fss && local.use_existing_subnets && !local.use_regional_subnet ? data.oci_core_subnet.mount_target_subnet[0].availability_domain : var.fss_availability_domain
16+
fss_availability_domain = var.add_fss ? (local.use_regional_subnet ? var.fss_availability_domain : (!var.add_existing_fss && !local.add_existing_mount_target ? data.oci_core_subnet.mount_target_subnet[0].availability_domain : var.fss_availability_domain)) : ""
1717
network_compartment_id = var.network_compartment_id == "" ? var.compartment_ocid : var.network_compartment_id
1818

1919
#dynamic group is based on the system generated tags for DG

terraform/main.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ module "network-vcn-config" {
5858
create_internet_gateway = var.wls_vcn_name != ""
5959
lb_destination_cidr = var.is_lb_private ? var.bastion_subnet_cidr : "0.0.0.0/0"
6060
add_fss = var.add_fss
61+
add_existing_mount_target = local.add_existing_mount_target
62+
add_existing_fss = var.add_existing_fss
6163
# If the module is empty (count is zero), an empty list is returned. If not, a list of lists of strings is returned.
6264
# By using flatten we make sure each entry in the map is a list of string, either with one element, or empty
6365
nsg_ids = {
@@ -283,7 +285,7 @@ module "network-wls-public-subnet" {
283285
/* Create private subnet for FSS */
284286
module "network-mount-target-private-subnet" {
285287
source = "./modules/network/subnet"
286-
count = var.add_fss && var.mount_target_subnet_id == "" ? 1 : 0
288+
count = var.add_fss && !local.add_existing_mount_target && !var.add_existing_fss && var.mount_target_subnet_id == "" ? 1 : 0
287289
compartment_id = local.network_compartment_id
288290
vcn_id = local.vcn_id
289291

@@ -395,7 +397,7 @@ module "validators" {
395397
mount_target_compartment_id = var.mount_target_compartment_id
396398
mount_target_id = var.mount_target_id
397399
existing_fss_id = var.existing_fss_id
398-
mount_target_availability_domain = var.add_existing_mount_target ? data.oci_file_storage_mount_targets.mount_targets[0].mount_targets[0].availability_domain : ""
400+
mount_target_availability_domain = local.add_existing_mount_target ? data.oci_file_storage_mount_targets.mount_targets[0].mount_targets[0].availability_domain : ""
399401

400402
create_policies = var.create_policies
401403
use_oci_logging = var.use_oci_logging
@@ -436,7 +438,7 @@ module "validators" {
436438

437439
module "fss" {
438440
source = "./modules/fss"
439-
count = var.existing_fss_id == "" && var.add_fss ? 1 : 0
441+
count = var.add_fss ? 1 : 0
440442

441443
compartment_id = var.compartment_ocid
442444
availability_domain = local.fss_availability_domain
@@ -445,10 +447,11 @@ module "fss" {
445447
vcn_cidr = var.wls_vcn_cidr != "" ? var.wls_vcn_cidr : data.oci_core_vcn.wls_vcn[0].cidr_block
446448
resource_name_prefix = var.service_name
447449
export_path = local.export_path
450+
existing_fss_id = var.existing_fss_id
448451
mount_target_id = var.mount_target_id
449452
mount_target_compartment_id = var.mount_target_compartment_id == "" ? var.compartment_ocid : var.mount_target_compartment_id
450-
mount_target_subnet_id = local.use_existing_subnets ? var.mount_target_subnet_id : module.network-mount-target-private-subnet[0].subnet_id
451-
mount_target_nsg_id = var.mount_target_subnet_id != "" ? (var.add_existing_nsg ? [var.existing_mount_target_nsg_id] : []) : element(module.network-mount-target-nsg[*].nsg_id, 0)
453+
mount_target_subnet_id = local.use_existing_subnets ? var.mount_target_subnet_id : (local.add_existing_mount_target ? "" : module.network-mount-target-private-subnet[0].subnet_id)
454+
mount_target_nsg_id = var.mount_target_subnet_id != "" || local.add_existing_mount_target ? (var.add_existing_nsg ? [var.existing_mount_target_nsg_id] : []) : element(module.network-mount-target-nsg[*].nsg_id, 0)
452455
tags = {
453456
defined_tags = local.defined_tags
454457
freeform_tags = local.free_form_tags
@@ -555,6 +558,7 @@ module "compute" {
555558
wls_domain_name = format("%s_domain", local.service_name_prefix)
556559
wls_server_startup_args = var.wls_server_startup_args
557560
wls_existing_vcn_id = var.wls_existing_vcn_id
561+
mount_vcn_id = var.mount_target_id != "" ? data.oci_core_subnet.mount_target_existing_subnet[0].vcn_id : (var.existing_fss_id != "" ? data.oci_core_subnet.mount_target_existing_subnet_by_fss[0].vcn_id : "")
558562
wls_vcn_cidr = var.wls_vcn_cidr != "" ? var.wls_vcn_cidr : element(concat(module.network-vcn.*.vcn_cidr, tolist([""])), 0)
559563
wls_version = var.wls_version
560564
wls_edition = var.wls_edition
@@ -578,7 +582,7 @@ module "compute" {
578582
add_fss = var.add_fss
579583
mount_ip = var.existing_fss_id != "" ? element(concat(data.oci_core_private_ip.mount_target_private_ips.*.ip_address, [""]), 0) : element(concat(module.fss[*].mount_ip, [""]), 0)
580584
mount_path = var.mount_path
581-
export_path = var.existing_export_path_id != "" ? element(concat(data.oci_file_storage_exports.export[*].exports[0].path, [""]), 0) : element(concat(module.fss[*].export_path, [""]), 0)
585+
export_path = local.export_path
582586

583587
db_existing_vcn_add_seclist = var.db_existing_vcn_add_secrule
584588
jrf_parameters = {

terraform/modules/compute/wls_compute/userdata/bootstrap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ if [ "$add_fss" == "true" ]; then
149149
mount_path=$(sudo su oracle -c 'python3 /opt/scripts/databag.py mount_path')
150150
export_path=$(sudo su oracle -c 'python3 /opt/scripts/databag.py export_path')
151151

152+
wls_existing_vcn_id=$(sudo su oracle -c 'python3 /opt/scripts/databag.py wls_existing_vcn_id')
153+
mount_vcn_id=$(sudo su oracle -c 'python3 /opt/scripts/databag.py mount_vcn_id')
154+
155+
if [ $mount_vcn_id != "" ]; then
156+
echo "Checking if the mount target and the WebLogic servers are in the same VCN" | log >> $log_file
157+
if [ "$wls_existing_vcn_id" == "$mount_vcn_id" ]; then
158+
echo "The mount target and the WebLogic servers are in the same VCN [$wls_existing_vcn_id]" | log >> $log_file
159+
else
160+
echo "The mount target is not in the same VCN as the WebLogic servers [$wls_existing_vcn_id, $mount_vcn_id]. Exiting" | log >> $log_file
161+
#clean up script
162+
/opt/scripts/tidyup.sh
163+
exit 1
164+
fi
165+
fi
166+
152167
echo "Executing fss mounting script" | log >> $log_file
153168
output=$(/opt/scripts/fss_mount.sh -i $mount_ip -p $mount_path -e $export_path 2>&1)
154169
exit_code=$?

terraform/modules/compute/wls_compute/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ variable "wls_existing_vcn_id" {
6565
default = ""
6666
}
6767

68+
variable "mount_vcn_id" {
69+
type = string
70+
description = "The OCID of the existing VCN where the mount target is located."
71+
default = ""
72+
}
73+
6874
variable "wls_vcn_cidr" {
6975
type = string
7076
description = "The CIDR of the VCN where the subnet the compute instance will be created is located"

terraform/modules/compute/wls_compute/wls_compute.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module "wls-instances" {
6060
total_vm_count = var.num_vm_instances
6161
assign_public_ip = var.assign_public_ip
6262
wls_existing_vcn_id = var.wls_existing_vcn_id
63+
mount_vcn_id = var.mount_vcn_id
6364
wls_subnet_ocid = var.subnet_id
6465
wls_vcn_cidr = var.wls_vcn_cidr
6566
network_compartment_id = var.network_compartment_id

terraform/modules/fss/export.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "oci_file_storage_export" "mount_export" {
55

66
#Required
77
export_set_id = oci_file_storage_export_set.mount_export_set.id
8-
file_system_id = join("", oci_file_storage_file_system.file_system.*.id)
8+
file_system_id = element(compact(tolist([var.existing_fss_id, join("", oci_file_storage_file_system.file_system.*.id)])), 0)
99
path = var.export_path
1010

1111
#Optional

terraform/modules/fss/fss.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
resource "oci_file_storage_file_system" "file_system" {
5-
5+
count = var.existing_fss_id == "" ? 1 : 0
66
#Required
77
availability_domain = var.availability_domain
88
compartment_id = var.compartment_id

terraform/modules/fss/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ variable "resource_name_prefix" {
6767
type = string
6868
description = "Prefix which will be used to create File Shared System resources"
6969
}
70+
71+
variable "existing_fss_id" {
72+
type = string
73+
description = "The OCID of the File System"
74+
}

0 commit comments

Comments
 (0)