Skip to content

Commit 1981f58

Browse files
authored
Merge pull request #123 from oracle-devrel/develop
Automation Toolkit Release v2024.4.0
2 parents 723fbbd + 3d1a6b7 commit 1981f58

File tree

547 files changed

+7469
-3600
lines changed

Some content is hidden

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

547 files changed

+7469
-3600
lines changed

Dockerfile

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ RUN microdnf install -y sudo && \
2020
USER $USERNAME
2121
WORKDIR /cd3user/oci_tools/
2222
COPY cd3_automation_toolkit cd3_automation_toolkit/
23+
COPY othertools othertools/
2324

2425
WORKDIR /cd3user/
2526

OCIWorkVMStack/scripts/installToolkit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ user_id=$(echo "$metadata" | jq -r '.metadata.current_user_ocid')
7575
cust_name=$(echo "$metadata" | jq -r '.metadata.tenancy_name')
7676
tenancy_id=$(echo "$metadata" | jq -r '.metadata.tenancy_ocid')
7777
config_region=$(echo "$metadata" | jq -r '.metadata.config_region')
78-
sudo sed -c -i "s/customer_name=.*/customer_name=$cust_name/" $tenancyconfig_properties
78+
sudo sed -c -i "s/prefix=.*/prefix=$cust_name/" $tenancyconfig_properties
7979
sudo sed -c -i "s/tenancy_ocid=.*/tenancy_ocid=$tenancy_id/" $tenancyconfig_properties
8080
sudo sed -c -i "s/region=.*/region=$config_region/" $tenancyconfig_properties
8181
sudo sed -c -i "s/user_ocid=.*/user_ocid=$user_id/" $tenancyconfig_properties

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
<br>
99

10-
[What's New](https://github.com/oracle-devrel/cd3-automation-toolkit/releases/tag/v2024.3.2) &nbsp;&nbsp;[Excel Templates](https://oracle-devrel.github.io/cd3-automation-toolkit/latest/excel-templates/) &nbsp;&nbsp;[CD3 Docs](https://oracle-devrel.github.io/cd3-automation-toolkit/)&nbsp;&nbsp; [Watch & Learn](https://www.youtube.com/playlist?list=PLPIzp-E1msrbJ3WawXVhzimQnLw5iafcp) &nbsp;&nbsp;[Blogs & Tutorials](https://oracle-devrel.github.io/cd3-automation-toolkit/latest/tutorials/) &nbsp;&nbsp;[Livelabs](https://apexapps.oracle.com/pls/apex/f?p=133:180:112501098061930::::wid:3724) &nbsp;&nbsp;[Slack Channel](https://oracle-devrel.github.io/cd3-automation-toolkit/latest/queries)
10+
[What's New](https://github.com/oracle-devrel/cd3-automation-toolkit/releases/tag/v2024.4.0) &nbsp;&nbsp;[Excel Templates](https://oracle-devrel.github.io/cd3-automation-toolkit/latest/excel-templates/) &nbsp;&nbsp;[CD3 Docs](https://oracle-devrel.github.io/cd3-automation-toolkit/)&nbsp;&nbsp; [Watch & Learn](https://www.youtube.com/playlist?list=PLPIzp-E1msrbJ3WawXVhzimQnLw5iafcp) &nbsp;&nbsp;[Blogs & Tutorials](https://oracle-devrel.github.io/cd3-automation-toolkit/latest/tutorials/) &nbsp;&nbsp;[Livelabs](https://apexapps.oracle.com/pls/apex/f?p=133:180:112501098061930::::wid:3724) &nbsp;&nbsp;[Slack Channel](https://oracle-devrel.github.io/cd3-automation-toolkit/latest/queries)
1111

1212
<br>
1313

1414

15-
CD3 stands for **Cloud Deployment Design Deliverable**. The CD3 Automation toolkit enables you to effortlessly Build, Export and Manage OCI (Oracle Cloud Infrastruture) resources by converting Excel templates to fully functional Terraform modules within minutes ⚡️⚡️ .
15+
CD3 stands for **Cloud Deployment Design Deliverable**. The CD3 Automation toolkit enables you to effortlessly Build, Export and Manage OCI (Oracle Cloud Infrastructure) resources by converting Excel templates to fully functional Terraform modules within minutes ⚡️⚡️ .
1616

1717
Additionally, the toolkit also supports seamless resource management using OCI DevOps GIT service and Jenkins Pipelines.
1818

cd3_automation_toolkit/Compute/create_terraform_dedicatedhosts.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ def create_terraform_dedicatedhosts(inputfile, outdir, service_dir,prefix, ct):
130130
tfStr[reg] = template.render(count=0, region=reg).replace(src, tfStr[reg] + "\n" + src)
131131
tfStr[reg] = "".join([s for s in tfStr[reg].strip().splitlines(True) if s.strip("\r\n").strip()])
132132

133-
resource = sheetName.lower()
134-
commonTools.backup_file(reg_out_dir + "/", resource, auto_tfvars_filename)
135-
136133
# Write to TF file
137134
outfile = reg_out_dir + "/" + auto_tfvars_filename
138135
tfStr[reg] = "".join([s for s in tfStr[reg].strip().splitlines(True) if s.strip("\r\n").strip()])

cd3_automation_toolkit/Compute/create_terraform_instances.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def create_terraform_instances(inputfile, outdir, service_dir, prefix, ct):
5353
tfStr[eachregion] = ''
5454
boot_policy_tfStr[eachregion] = ''
5555

56-
subnets = parseSubnets(filename)
56+
#subnets = parseSubnets(filename)
5757

5858
for i in df.index:
5959
region = str(df.loc[i, 'Region'])
@@ -93,9 +93,9 @@ def create_terraform_instances(inputfile, outdir, service_dir, prefix, ct):
9393
df.loc[i, 'Shape']).lower() == 'nan' or str(df.loc[i, 'Compartment Name']).lower() == 'nan' or str(
9494
df.loc[i, 'Pub Address']).lower() == 'nan' or str(
9595
df.loc[i, 'Availability Domain(AD1|AD2|AD3)']).lower() == 'nan' or str(
96-
df.loc[i, 'Subnet Name']).lower() == 'nan' or str(df.loc[i, 'Source Details']).lower() == 'nan'):
96+
df.loc[i, 'Network Details']).lower() == 'nan' or str(df.loc[i, 'Source Details']).lower() == 'nan'):
9797
print(
98-
"\nOne/All of the Column/Columns from Region, Shape, Compartment Name, Availability Domain, Display Name, Pub Address, Source Details and Subnet Name is empty in Instances sheet of CD3..exiting...Please check.")
98+
"\nOne/All of the Column/Columns from Region, Shape, Compartment Name, Availability Domain, Display Name, Pub Address, Source Details and Network Details is empty in Instances sheet of CD3..exiting...Please check.")
9999
exit(1)
100100

101101
# Perform the plugin match
@@ -137,25 +137,30 @@ def create_terraform_instances(inputfile, outdir, service_dir, prefix, ct):
137137
columnvalue = columnvalue.strip()
138138
tempdict = {'shape': [columnvalue]}
139139

140-
if columnname == "Subnet Name":
141-
subnet_tf_name = columnvalue.strip()
142-
if ("ocid1.subnet.oc1" in subnet_tf_name):
143-
network_compartment_id = ""
140+
subnet_id = ''
141+
network_compartment_id = ''
142+
vcn_name = ''
143+
if columnname == "Network Details":
144+
columnvalue = columnvalue.strip()
145+
if ("ocid1.subnet.oc" in columnvalue):
146+
network_compartment_id = "root"
144147
vcn_name = ""
145-
subnet_id = subnet_tf_name
146-
else:
147-
try:
148-
key = region, subnet_tf_name
149-
network_compartment_id = subnets.vcn_subnet_map[key][0]
150-
vcn_name = subnets.vcn_subnet_map[key][1]
151-
subnet_id = subnets.vcn_subnet_map[key][2]
152-
except Exception as e:
153-
print("Invalid Subnet Name specified for row " + str(
154-
i + 3) + ". It Doesnt exist in Subnets sheet. Exiting!!!")
148+
subnet_id = columnvalue
149+
elif columnvalue.lower() != 'nan' and columnvalue.lower() != '':
150+
if len(columnvalue.split("@")) == 2:
151+
network_compartment_id = commonTools.check_tf_variable(columnvalue.split("@")[0].strip())
152+
vcn_subnet_name = columnvalue.split("@")[1].strip()
153+
else:
154+
network_compartment_id = commonTools.check_tf_variable(
155+
str(df.loc[i, 'Compartment Name']).strip())
156+
vcn_subnet_name = columnvalue
157+
if ("::" not in vcn_subnet_name):
158+
print("Invalid Network Details format specified for row " + str(i + 3) + ". Exiting!!!")
155159
exit(1)
156-
157-
tempdict = {'network_compartment_id': commonTools.check_tf_variable(network_compartment_id),
158-
'vcn_name': vcn_name,
160+
else:
161+
vcn_name = vcn_subnet_name.split("::")[0].strip()
162+
subnet_id = vcn_subnet_name.split("::")[1].strip()
163+
tempdict = {'network_compartment_id': network_compartment_id, 'vcn_name': vcn_name,
159164
'subnet_id': subnet_id}
160165

161166
if columnname == 'Display Name':
@@ -255,9 +260,6 @@ def create_terraform_instances(inputfile, outdir, service_dir, prefix, ct):
255260
tfStr[reg] = template.render(count=0, region=reg).replace(src, tfStr[reg] + "\n" + src)
256261
tfStr[reg] = "".join([s for s in tfStr[reg].strip().splitlines(True) if s.strip("\r\n").strip()])
257262

258-
resource = sheetName.lower()
259-
commonTools.backup_file(reg_out_dir + "/", resource, auto_tfvars_filename)
260-
261263
# Write to TF file
262264
outfile = reg_out_dir + "/" + auto_tfvars_filename
263265
tfStr[reg] = "".join([s for s in tfStr[reg].strip().splitlines(True) if s.strip("\r\n").strip()])

cd3_automation_toolkit/Compute/export_dedicatedvmhosts_nonGreenField.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import oci
1212
import os
13+
import subprocess as sp
1314

1415
from oci.config import DEFAULT_LOCATION
1516
from commonTools import *
@@ -18,9 +19,11 @@
1819
oci_obj_names = {}
1920

2021

21-
def print_dedicatedvmhosts(region, dedicatedvmhost, values_for_column, ntk_compartment_name):
22+
def print_dedicatedvmhosts(region, dedicatedvmhost, values_for_column, ntk_compartment_name,state):
2223
dedicatedvmhost_tf_name = commonTools.check_tf_variable(dedicatedvmhost.display_name)
23-
importCommands[region.lower()].write("\nterraform import \"module.dedicated-hosts[\\\"" +dedicatedvmhost_tf_name+ "\\\"].oci_core_dedicated_vm_host.dedicated_vm_host\" " + str(dedicatedvmhost.id))
24+
tf_resource = f'module.dedicated-hosts[\\"{dedicatedvmhost_tf_name}\\"].oci_core_dedicated_vm_host.dedicated_vm_host'
25+
if tf_resource not in state["resources"]:
26+
importCommands[region.lower()] += f'\n{tf_or_tofu} import "{tf_resource}" {str(dedicatedvmhost.id)}'
2427

2528
for col_header in values_for_column:
2629
if col_header == 'Region':
@@ -50,7 +53,10 @@ def export_dedicatedvmhosts(inputfile, outdir, service_dir, config, signer, ct,
5053
global importCommands
5154
global cd3file
5255
global reg
53-
global values_for_column
56+
global values_for_column,tf_or_tofu
57+
58+
tf_or_tofu = ct.tf_or_tofu
59+
tf_state_list = [tf_or_tofu, "state", "list"]
5460

5561

5662
cd3file = inputfile
@@ -69,39 +75,48 @@ def export_dedicatedvmhosts(inputfile, outdir, service_dir, config, signer, ct,
6975
print("\nCD3 excel file should not be opened during export process!!!")
7076
print("Tabs- DedicatedVMHosts will be overwritten during export process!!!\n")
7177

78+
# Fetch DVH Details
79+
print("\nFetching details of Dedicated VM Hosts...")
80+
7281
# Create backups
73-
resource = 'tf_import_' + sheetName.lower()
74-
file_name = 'tf_import_commands_' + sheetName.lower() + '_nonGF.sh'
82+
resource = 'import_' + sheetName.lower()
83+
file_name = 'import_commands_' + sheetName.lower() + '.sh'
84+
7585
for reg in export_regions:
7686
script_file = f'{outdir}/{reg}/{service_dir}/'+file_name
7787
if (os.path.exists(script_file)):
7888
commonTools.backup_file(outdir + "/" + reg+"/"+service_dir, resource, file_name)
79-
importCommands[reg] = open(script_file, "w")
80-
importCommands[reg].write("#!/bin/bash")
81-
importCommands[reg].write("\n")
82-
importCommands[reg].write("terraform init")
83-
84-
# Fetch Block Volume Details
85-
print("\nFetching details of Dedicated VM Hosts...")
89+
importCommands[reg] = ''
8690

87-
for reg in export_regions:
88-
importCommands[reg].write("\n\n######### Writing import for Dedicated VM Hosts #########\n\n")
8991
config.__setitem__("region", ct.region_dict[reg])
92+
state = {'path': f'{outdir}/{reg}/{service_dir}', 'resources': []}
93+
try:
94+
byteOutput = sp.check_output(tf_state_list, cwd=state["path"], stderr=sp.DEVNULL)
95+
output = byteOutput.decode('UTF-8').rstrip()
96+
for item in output.split('\n'):
97+
state["resources"].append(item.replace("\"", "\\\""))
98+
except Exception as e:
99+
pass
90100
region = reg.capitalize()
91101

92102
compute_client = oci.core.ComputeClient(config=config,retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY, signer=signer)
93103

94104
for ntk_compartment_name in export_compartments:
95105
dedicatedvmhosts = oci.pagination.list_call_get_all_results(compute_client.list_dedicated_vm_hosts,compartment_id=ct.ntk_compartment_ids[ntk_compartment_name], lifecycle_state="ACTIVE")
106+
96107
for dedicatedvmhost in dedicatedvmhosts.data:
97108
dedicatedvmhost=compute_client.get_dedicated_vm_host(dedicatedvmhost.id).data
98-
print_dedicatedvmhosts(region, dedicatedvmhost,values_for_column, ntk_compartment_name)
109+
print_dedicatedvmhosts(region, dedicatedvmhost,values_for_column, ntk_compartment_name,state)
99110

100-
# write data into file
111+
# writing data
101112
for reg in export_regions:
102-
script_file = f'{outdir}/{reg}/{service_dir}/'+file_name
103-
with open(script_file, 'a') as importCommands[reg]:
104-
importCommands[reg].write('\n\nterraform plan\n')
113+
script_file = f'{outdir}/{reg}/{service_dir}/' + file_name
114+
115+
init_commands = f'\n######### Writing import for Dedicated VM Hosts #########\n\n#!/bin/bash\n{tf_or_tofu} init'
116+
if importCommands[reg] != "":
117+
importCommands[reg] += f'\n{tf_or_tofu} plan\n'
118+
with open(script_file, 'a') as importCommandsfile:
119+
importCommandsfile.write(init_commands + importCommands[reg])
105120

106121
commonTools.write_to_cd3(values_for_column, cd3file, "DedicatedVMHosts")
107122

0 commit comments

Comments
 (0)