Skip to content

Commit 633b328

Browse files
authored
Merge pull request #91 from oracle-devrel/develop
Automation Toolkit Release v2024.2.0
2 parents 928b012 + 4688e7a commit 633b328

File tree

252 files changed

+12934
-2028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+12934
-2028
lines changed

.gitignore

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,6 @@
1-
# General
21
.DS_Store
3-
.AppleDouble
4-
.LSOverride
5-
.terraform*
62
.idea
73
*.log
84
tmp/
95

10-
__pycache__/
11-
# Icon must end with two \r
12-
Icon
13-
14-
15-
# Thumbnails
16-
._*
17-
18-
# Files that might appear in the root of a volume
19-
.DocumentRevisions-V100
20-
.fseventsd
21-
.Spotlight-V100
22-
.TemporaryItems
23-
.Trashes
24-
.VolumeIcon.icns
25-
.com.apple.timemachine.donotpresent
26-
27-
# Directories potentially created on remote AFP share
28-
.AppleDB
29-
.AppleDesktop
30-
Network Trash Folder
31-
Temporary Items
32-
.apdisk
33-
34-
# ignore common security keys
35-
.key
36-
.crt
37-
.csr
38-
.pem
6+
__pycache__/

OCIWorkVMStack/data_sources.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
data "oci_identity_availability_domain" "ad" {
3+
compartment_id = var.tenancy_ocid
4+
ad_number = var.availability_domain_number
5+
}
6+
*/
7+
8+
data "oci_core_subnet" "subnet" {
9+
#Required
10+
count = var.vcn_strategy == "Use Existing VCN" ? 1 : 0
11+
subnet_id = var.existing_subnet_id
12+
}
13+
14+
data "oci_identity_compartment" "compartment" {
15+
#Required
16+
id = local.instance_compartment_ocid
17+
depends_on = [module.instance]
18+
}
19+
20+
data "oci_core_images" "oracle_linux" {
21+
compartment_id = var.tenancy_ocid
22+
operating_system = "Oracle Linux"
23+
shape = var.instance_shape
24+
sort_by = "TIMECREATED"
25+
sort_order = "DESC"
26+
state = "AVAILABLE"
27+
28+
# filter restricts to OL
29+
filter {
30+
name = "operating_system_version"
31+
values = ["${local.os_version}"]
32+
regex = false
33+
}
34+
}

OCIWorkVMStack/image_subscription.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#Get Image Agreement
2+
resource "oci_core_app_catalog_listing_resource_version_agreement" "mp_image_agreement" {
3+
count = local.mp_subscription_enabled
4+
listing_id = local.listing_id
5+
listing_resource_version = local.listing_resource_version
6+
}
7+
8+
#Accept Terms and Subscribe to the image, placing the image in a particular compartment
9+
resource "oci_core_app_catalog_subscription" "mp_image_subscription" {
10+
count = local.mp_subscription_enabled
11+
compartment_id = var.instance_compartment_ocid
12+
eula_link = oci_core_app_catalog_listing_resource_version_agreement.mp_image_agreement[0].eula_link
13+
listing_id = oci_core_app_catalog_listing_resource_version_agreement.mp_image_agreement[0].listing_id
14+
listing_resource_version = oci_core_app_catalog_listing_resource_version_agreement.mp_image_agreement[0].listing_resource_version
15+
oracle_terms_of_use_link = oci_core_app_catalog_listing_resource_version_agreement.mp_image_agreement[0].oracle_terms_of_use_link
16+
signature = oci_core_app_catalog_listing_resource_version_agreement.mp_image_agreement[0].signature
17+
time_retrieved = oci_core_app_catalog_listing_resource_version_agreement.mp_image_agreement[0].time_retrieved
18+
19+
timeouts {
20+
create = "20m"
21+
}
22+
}
23+
24+
# Gets the partner image subscription
25+
data "oci_core_app_catalog_subscriptions" "mp_image_subscription" {
26+
count = local.mp_subscription_enabled
27+
28+
compartment_id = var.instance_compartment_ocid
29+
listing_id = local.listing_id
30+
31+
filter {
32+
name = "listing_resource_version"
33+
values = [local.listing_resource_version]
34+
}
35+
}

OCIWorkVMStack/installToolkit.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
3+
username=cd3user
4+
sudo mkdir -p /$username/mount_path
5+
logfile="/$username/mount_path/installToolkit.log"
6+
toolkit_dir="/tmp/githubCode"
7+
start=$(date +%s.%N)
8+
sudo sh -c "echo '########################################################################' >> /etc/motd"
9+
sudo sh -c "echo ' Welcome to CD3 Automation Toolkit WorkVM' >> /etc/motd"
10+
sudo sh -c "echo '########################################################################' >> /etc/motd"
11+
sudo sh -c "echo 'Please wait for couple of minutes for container to become active if you' >> /etc/motd"
12+
sudo sh -c "echo 'are logging in for first time to after VM Provisioning. Toolkit initial' >> /etc/motd"
13+
sudo sh -c "echo 'setup log is present at - /cd3user/mount_path/installToolkit.log' >> /etc/motd"
14+
sudo sh -c "echo 'To verify podman container run command: sudo podman ps -a' >> /etc/motd"
15+
sudo sh -c "echo 'To connect to container run command: sudo podman exec -it cd3_toolkit bash' >> /etc/motd"
16+
sudo sh -c "echo 'if you want to stop seeing these messages at login remove in /etc/motd' >> /etc/motd"
17+
sudo sh -c "echo '###########################################################################' >> /etc/motd"
18+
19+
stop_exec () {
20+
if [[ $? -ne 0 ]] ; then
21+
echo $? >> $logfile 2>&1
22+
echo "Error encountered in CD3 Automation Toolkit Container Setup. Please do setup Manually" >> $logfile 2>&1
23+
exit 1
24+
fi
25+
}
26+
27+
sudo systemctl stop oracle-cloud-agent.service
28+
cd /etc/yum.repos.d/
29+
for i in $( ls *.osms-backup ); do sudo mv $i ${i%.*}; done
30+
31+
echo "########################################################" >> $logfile 2>&1
32+
echo " Setting SELinux to permissive " >> $logfile 2>&1
33+
echo "########################################################" >> $logfile 2>&1
34+
sudo setenforce 0
35+
sudo sed -c -i "s/\SELINUX=.*/SELINUX=permissive/" /etc/sysconfig/selinux
36+
sudo getenforce >> $logfile 2>&1
37+
stop_exec
38+
echo "********************************************************" >> $logfile 2>&1
39+
40+
echo "########################################################" >> $logfile 2>&1
41+
echo " Installing git on the workvm " >> $logfile 2>&1
42+
echo "########################################################" >> $logfile 2>&1
43+
sudo yum install -y git >> $logfile 2>&1
44+
stop_exec
45+
echo "git installation completed successfully" >> $logfile 2>&1
46+
echo "********************************************************" >> $logfile 2>&1
47+
48+
echo "########################################################" >> $logfile 2>&1
49+
echo " Installing Podman on the workvm " >> $logfile 2>&1
50+
echo "########################################################" >> $logfile 2>&1
51+
osrelase=`cat /etc/oracle-release`
52+
if [[ $osrelase == "Oracle Linux Server release 7".* ]] ; then
53+
sudo yum install -y podman podman-docker >> $logfile 2>&1
54+
stop_exec
55+
else
56+
sudo yum install -y podman podman-docker >> $logfile 2>&1
57+
stop_exec
58+
sudo systemctl enable podman.service
59+
sudo systemctl start podman.service
60+
stop_exec
61+
fi
62+
sudo podman --version >> $logfile 2>&1
63+
stop_exec
64+
echo "podman installation completed successfully" >> $logfile 2>&1
65+
echo "********************************************************" >> $logfile 2>&1
66+
67+
echo "########################################################" >> $logfile 2>&1
68+
echo "Downloading CD3 Automation Toolkit Code from Github " >> $logfile 2>&1
69+
echo "########################################################" >> $logfile 2>&1
70+
sudo git clone https://github.com/oracle-devrel/cd3-automation-toolkit.git $toolkit_dir >> $logfile 2>&1
71+
stop_exec
72+
sudo ls -la /tmp/githubCode >> $logfile 2>&1
73+
echo "Downloading CD3 Automation Toolkit Code from Github completed successfully" >> $logfile 2>&1
74+
echo "********************************************************" >> $logfile 2>&1
75+
76+
echo "########################################################" >> $logfile 2>&1
77+
echo "Building container image for CD3 Automation Toolkit " >> $logfile 2>&1
78+
echo "########################################################" >> $logfile 2>&1
79+
cd /tmp
80+
cd githubCode
81+
echo "Building CD3 Automation Toolkit Podman Image " >> $logfile 2>&1
82+
sudo podman build --platform linux/amd64 -t cd3_toolkit -f Dockerfile --pull --no-cache . >> $logfile 2>&1
83+
#stop_exec
84+
sudo podman images >> $logfile 2>&1
85+
stop_exec
86+
echo " " >> $logfile 2>&1
87+
echo " ********************************************** " >> $logfile 2>&1
88+
89+
echo "########################################################" >> $logfile 2>&1
90+
echo "Setting Up cd3user for CD3 Automation Toolkit " >> $logfile 2>&1
91+
echo "########################################################" >> $logfile 2>&1
92+
sudo useradd -u 1001 $username >> $logfile 2>&1
93+
sudo sh -c "echo $username ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$username" >> $logfile 2>&1
94+
sudo chmod 0440 /etc/sudoers.d/$username >> $logfile 2>&1
95+
stop_exec
96+
sudo chmod 775 -R /$username >> $logfile 2>&1
97+
stop_exec
98+
sudo chown -R $username:$username /$username >> $logfile 2>&1
99+
stop_exec
100+
sudo usermod -aG $username opc >> $logfile 2>&1
101+
stop_exec
102+
sudo mkdir /home/$username/.ssh >> $logfile 2>&1
103+
stop_exec
104+
sudo chown -R $username:$username /home/$username/.ssh >> $logfile 2>&1
105+
stop_exec
106+
sudo chmod 700 /home/$username/.ssh >> $logfile 2>&1
107+
stop_exec
108+
sudo cp /home/opc/.ssh/authorized_keys /home/$username/.ssh/authorized_keys >> $logfile 2>&1
109+
stop_exec
110+
sudo chown -R $username:$username /home/$username/.ssh/authorized_keys >> $logfile 2>&1
111+
stop_exec
112+
sudo chmod 600 /home/$username/.ssh/authorized_keys >> $logfile 2>&1
113+
stop_exec
114+
sudo id cd3user >> $logfile 2>&1
115+
stop_exec
116+
echo " Successfully created cd3user with required permission " >> $logfile 2>&1
117+
echo " ********************************************** " >> $logfile 2>&1
118+
119+
echo "########################################################" >> $logfile 2>&1
120+
echo "Setting Up CD3 Automation Toolkit Podman Container " >> $logfile 2>&1
121+
echo "########################################################" >> $logfile 2>&1
122+
sudo podman run --name cd3_toolkit -it -p 8443:8443 -d -v /cd3user/mount_path:/cd3user/tenancies cd3_toolkit bash >> $logfile 2>&1
123+
stop_exec
124+
sudo podman ps -a >> $logfile 2>&1
125+
stop_exec
126+
echo " " >> $logfile 2>&1
127+
echo "Successfully Created podman Container named as cd3_toolkit " >> $logfile 2>&1
128+
echo "Connect to Container using command - sudo podman exec -it cd3_toolkit bash " >> $logfile 2>&1
129+
echo "########################################################" >> $logfile 2>&1
130+
131+
sudo systemctl start oracle-cloud-agent.service
132+
133+
duration_sec=$(echo "$(date +%s.%N) - $start" | bc)
134+
duration_min=$(echo "$duration_sec%3600/60" | bc)
135+
execution_time=`printf "%.2f seconds" $duration_sec`
136+
echo "Script Execution Time in Seconds: $execution_time" >> $logfile 2>&1
137+
echo "Script Execution Time in Minutes: approx $duration_min Minutes" >> $logfile 2>&1

OCIWorkVMStack/locals.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
locals {
2+
instance_compartment_ocid = var.instance_compartment_strategy == "Create New Compartment - Stack must be provisioned in home region" ? module.compartment[0].compartment_tf_id : var.instance_compartment_ocid
3+
#vcn_compartment_ocid = var.vcn_strategy == "Use Existing VCN" ? var.vcn_compartment_ocid : module.compartment[0].compartment_tf_id
4+
vcn_compartment_ocid = var.vcn_strategy == "Use Existing VCN" ? var.vcn_compartment_ocid : local.instance_compartment_ocid
5+
nsg_id = var.assign_existing_nsg == true ? var.existing_nsg_id : null
6+
is_public_sub = var.vcn_strategy == "Use Existing VCN" ? !data.oci_core_subnet.subnet[0].prohibit_public_ip_on_vnic : false
7+
assignPublicIP = var.vcn_strategy == "Create New VCN" ? var.assign_public_ip : ((local.is_public_sub && var.assign_publicip_existing_subnet) == true ? true : false)
8+
9+
10+
# Logic to select Oracle Autonomous Linux 7 platform image (version pegged in data source filter)
11+
#platform_image_id = data.oci_core_images.ol7.images[0].id
12+
# Logic to choose a custom image or a marketplace image.
13+
#compute_image_id = var.mp_subscription_enabled ? var.mp_listing_resource_id : var.instance_image_ocid
14+
# Local to control subscription to Marketplace image.
15+
mp_subscription_enabled = var.mp_subscription_enabled ? 1 : 0
16+
17+
# Marketplace Image listing variables - required for subscription only
18+
listing_id = var.mp_listing_id
19+
listing_resource_id = var.mp_listing_resource_id
20+
listing_resource_version = var.mp_listing_resource_version
21+
22+
os_version = var.instance_os_version == "Oracle-Linux-9" ? 9 : (var.instance_os_version == "Oracle-Linux-8" ? 8 : 7.9)
23+
24+
instance_image_ocid = data.oci_core_images.oracle_linux.images[0].id
25+
26+
}

OCIWorkVMStack/main.tf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
3+
*/
4+
5+
module "compartment" {
6+
source = "./modules/compartment"
7+
count = var.instance_compartment_strategy == "Create New Compartment - Stack must be provisioned in home region" ? 1 : 0
8+
compartment_id = var.parent_compartment_ocid
9+
compartment_name = var.new_compartment_name
10+
}
11+
12+
# Create VCN/network resources
13+
14+
module "network" {
15+
source = "./modules/network"
16+
vcn_compartment_ocid = local.vcn_compartment_ocid
17+
vcn_strategy = var.vcn_strategy
18+
vcn_name = var.vcn_name
19+
vcn_cidr = var.vcn_cidr
20+
vcn_dns_label = var.vcn_dns_label
21+
subnet_name = var.subnet_name
22+
subnet_type = var.subnet_type
23+
subnet_cidr = var.subnet_cidr
24+
subnet_dns_label = var.subnet_dns_label
25+
existing_drg_id = var.existing_drg_id
26+
drg_attachment = var.drg_attachment
27+
source_cidr = var.source_cidr
28+
}
29+
30+
module "instance" {
31+
source = "./modules/compute"
32+
vcn_strategy = var.vcn_strategy == "Create New VCN" ? 1 : 0
33+
instance_image_ocid = local.instance_image_ocid
34+
subnet_id = var.vcn_strategy == "Create New VCN" ? module.network.subnet_id : var.existing_subnet_id
35+
nsg_id = var.vcn_strategy == "Create New VCN" ? module.network.nsg_id : local.nsg_id
36+
instance_compartment_ocid = local.instance_compartment_ocid
37+
instance_name = var.instance_name
38+
instance_shape = var.instance_shape
39+
instance_ram = var.instance_ram
40+
instance_ocpus = var.instance_ocpus
41+
instance_ad = var.instance_ad
42+
instance_fd = var.instance_fd
43+
ssh_public_key = var.ssh_public_key
44+
assign_public_ip = local.assignPublicIP
45+
cloud_init_script = var.cloud_init_script
46+
}
47+
48+
# This resource will wait for ~ 15 min to cloud init script to completed cd3 related steps
49+
resource "time_sleep" "wait" {
50+
depends_on = [module.instance]
51+
create_duration = "480s"
52+
53+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
3+
############################
4+
# Resource Block - Identity
5+
# Create Compartments
6+
############################
7+
8+
resource "oci_identity_compartment" "compartment" {
9+
10+
#Required
11+
compartment_id = var.compartment_id != null ? var.compartment_id : var.tenancy_ocid
12+
description = var.compartment_description
13+
name = var.compartment_name
14+
15+
#Optional
16+
defined_tags = var.defined_tags
17+
freeform_tags = var.freeform_tags
18+
enable_delete = var.enable_delete
19+
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
3+
############################
4+
# Output Block - Identity
5+
# Create Compartments
6+
############################
7+
8+
output "compartment_tf_id" {
9+
description = "Compartment ocid"
10+
value = oci_identity_compartment.compartment.id
11+
}

0 commit comments

Comments
 (0)