Skip to content

Commit 49ab4dc

Browse files
authored
Merge pull request #20 from oracle-devrel/develop
v10 Commit Apprved
2 parents 8168de2 + 46e3979 commit 49ab4dc

File tree

115 files changed

+3786
-360
lines changed

Some content is hidden

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

115 files changed

+3786
-360
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ The CD3 Automation toolkit has been developed to help in automating the OCI reso
99
It reads input data in the form of CD3 Excel sheets and generates the terraform files instead of handling the task through the OCI console manually. The toolkit also reverse engineers the components in OCI back to the Excel sheet and Terraform configuration. This generated Terraform code can be used by the OCI Resource Manager or leveraged by the organisations’ CI/CD processes.
1010
<br><br>
1111
<img width="748" alt="Screenshot 2022-12-30 at 11 57 41 AM" src="https://user-images.githubusercontent.com/111430850/210614513-5d2e97a6-3c1e-4a2b-a793-3a1b6410c856.png">
12-
<br><br>
13-
14-
`To ease the execution of toolkit, we have provided the steps to build an image which encloses the code base and its package dependencies. Follow the steps provided below to clone the repo and build the image.`
15-
<br><br>
12+
<br>
1613

1714
#### OCI Services Currently Supported by CD3
18-
<img width="748" alt="Screenshot 2022-12-30 at 1 05 59 PM" src="https://user-images.githubusercontent.com/103475219/210046038-91acacfd-5d65-4bc3-a1a8-90d425d2e3d3.png">
1915

16+
| OCI Services | Details |
17+
| --------- | ----------- |
18+
| IAM | Compartments, Groups, Dynamic Groups, Policies |
19+
| Network | VCNs, Subnets, DRGs, IGWs, NGWs, LPGs, Route Tables, DRG Route, Tables, Security Lists, Network Security Groups, Application Load Balancer, Network Load Balancers |
20+
| Governance | Tags (Namespaces, Tag Keys, Defined Tags, Default Tags, Cost Tracking) |
21+
| Compute | Instances – VM, BM, Dedicated VM Hosts |
22+
| Storage | FSS, Block and Boot Volumes, Backup Policies |
23+
| Database | Exa Infra, ExaCS, DB Systems VM and BM, ATP, ADW |
24+
| Management Services | Events, Notifications, Alarms, Service Connector Hub (SCH) |
25+
| Developer Services | Resource Manager, Oracle Kubernetes Engine (OKE) |
26+
| CIS Landing Zone Compliance | Download CIS Report Script, Execute CIS Report Script, VCN Flow Logs, Cloud Guard, Object Storage, Key Vault, Budget |
2027

28+
`To ease the execution of toolkit, we have provided the steps to build an image which encloses the code base and its package dependencies. Follow the steps provided below to clone the repo and build the image.`
29+
<br>
2130

2231
## Getting Started
2332

cd3_automation_toolkit/Compute/export_dedicatedvmhosts_nonGreenField.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ def export_dedicatedvmhosts(inputfile, _outdir, _config, network_compartments=[]
123123
dedicatedvmhost=compute_client.get_dedicated_vm_host(dedicatedvmhost.id).data
124124
print_dedicatedvmhosts(region, dedicatedvmhost,values_for_column, ntk_compartment_name)
125125

126-
if "linux" in sys.platform:
127-
os.chmod(script_file, 0o755)
128-
129126
commonTools.write_to_cd3(values_for_column, cd3file, "DedicatedVMHosts")
130127

131128
print("Dedicated VM Hosts exported to CD3\n")

cd3_automation_toolkit/Compute/export_instances_nonGreenField.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ def __get_instances_info(compartment_name, compartment_id, reg_name, config,disp
9393
bc = oci.core.BlockstorageClient(config, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY)
9494
instance_info = oci.pagination.list_call_get_all_results(compute.list_instances, compartment_id=compartment_id)
9595
# print(instance_info.data)
96-
vnic_defined_tags=""
97-
vnic_freeform_tags=""
96+
9897
for ins in instance_info.data:
9998
ins_details = compute.get_instance(instance_id=ins.id)
10099
# print(ins_details.data)
@@ -181,7 +180,8 @@ def __get_instances_info(compartment_name, compartment_id, reg_name, config,disp
181180
vnic_info = network.get_vnic(vnic_id=vnic_id).data
182181

183182
# print(vnic_info)
184-
183+
vnic_defined_tags = ""
184+
vnic_freeform_tags = ""
185185
for namespace,tagkey in vnic_info.defined_tags.items():
186186
for tag,value in tagkey.items():
187187
vnic_defined_tags=vnic_defined_tags+";"+namespace+"."+tag+"="+value
@@ -372,8 +372,6 @@ def export_instances(inputfile, outdir, config, network_compartments=[], display
372372
script_file = f'{outdir}/{reg}/tf_import_commands_instances_nonGF.sh'
373373
with open(script_file, 'a') as importCommands[reg]:
374374
importCommands[reg].write('\n\nterraform plan\n')
375-
if "linux" in sys.platform:
376-
os.chmod(script_file, 0o755)
377375

378376
commonTools.write_to_cd3(values_for_column_instances, cd3file, "Instances")
379377
print("{0} Instance Details exported into CD3.\n".format(len(values_for_column_instances["Region"])))

cd3_automation_toolkit/Compute/templates/dedicatedvmhosts-template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Dedicated VM Hosts - tfvars
77
# Allowed Values:
88
# compartment_id and network_compartment_id can be the ocid or the name of the compartment hierarchy delimited by double hiphens "--"
9-
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Network-root-cpt--Network" where "Network-root-cpt" is the parent of "Network" compartment
9+
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "AppDev--Prod" where "AppDev" is the parent of "Prod" compartment
1010
# Sample import command for Dedicated VM Hosts:
1111
# terraform import "module.dedicated-hosts[\"<<dedicated_hosts terraform variable name>>\"].oci_core_dedicated_vm_host.dedicated_vm_host" <<dedicated vm host ocid>>
1212
############################

cd3_automation_toolkit/Compute/templates/instances-template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
# vcn_name must be the name of the VCN as in OCI
99
# subnet_id can be the ocid of the subnet or the name as in OCI
1010
# compartment_id and network_compartment_id can be the ocid or the name of the compartment hierarchy delimited by double hiphens "--"
11-
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Network-root-cpt--Network" where "Network-root-cpt" is the parent of "Network" compartment
11+
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "AppDev--Prod" where "AppDev" is the parent of "Prod" compartment
1212
# Sample import command for Instance and volume backup policy:
13-
# terraform import "module.instances[\"<<instances terraform variable name>>\"].oci_core_instance.instance" <<instance ocid>>
14-
# terraform import "module.instances[\"<<instances terraform variable name>>\"].oci_core_volume_backup_policy_assignment.volume_backup_policy_assignment[0]" <<volume backup policy ocid>>
13+
# terraform import "module.instances[\"<<instance terraform variable name>>\"].oci_core_instance.instance" <<instance ocid>>
14+
# terraform import "module.instances[\"<<instance terraform variable name>>\"].oci_core_volume_backup_policy_assignment.volume_backup_policy_assignment[0]" <<volume backup policy ocid>>
1515
############################
1616

1717
instances = {

cd3_automation_toolkit/Database/create_terraform_dbsystems_vm_bm.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def create_terraform_dbsystems_vm_bm(inputfile, outdir, prefix, config=DEFAULT_L
4444
oname = {}
4545
tfStr = {}
4646
ADS = ["AD1", "AD2", "AD3"]
47+
subnets = parseSubnets(filename)
4748

4849
# Load the template file
4950
file_loader = FileSystemLoader(f'{Path(__file__).parent}/templates')
@@ -157,10 +158,28 @@ def create_terraform_dbsystems_vm_bm(inputfile, outdir, prefix, config=DEFAULT_L
157158
tempdict = {'display_tf_name': display_tf_name}
158159

159160
if columnname == 'Subnet Name':
160-
columnvalue = commonTools.check_tf_variable(columnvalue)
161-
162-
if columnname == 'Backup Subnet Name':
163-
columnvalue = commonTools.check_tf_variable(columnvalue)
161+
subnet_tf_name = columnvalue.strip()
162+
if ("ocid1.subnet.oc1" in subnet_tf_name):
163+
network_compartment_id = ""
164+
vcn_name = ""
165+
subnet_id = subnet_tf_name
166+
else:
167+
try:
168+
key = region, subnet_tf_name
169+
network_compartment_id = subnets.vcn_subnet_map[key][0]
170+
vcn_name = subnets.vcn_subnet_map[key][1]
171+
subnet_id = subnets.vcn_subnet_map[key][2]
172+
except Exception as e:
173+
print("Invalid Subnet Name specified for row " + str(
174+
i + 3) + ". It Doesnt exist in Subnets sheet. Exiting!!!")
175+
exit()
176+
177+
tempdict = {'network_compartment_id': commonTools.check_tf_variable(network_compartment_id),
178+
'vcn_name': vcn_name,
179+
'subnet_id': subnet_id}
180+
181+
# if columnname == 'Backup Subnet Name':
182+
# columnvalue = commonTools.check_tf_variable(columnvalue)
164183

165184

166185
if columnname == 'Availability Domain(AD1|AD2|AD3)':

cd3_automation_toolkit/Database/create_terraform_exa_vmclusters.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def create_terraform_exa_vmclusters(inputfile, outdir, prefix, config=DEFAULT_LO
6161

6262
# List of the column headers
6363
dfcolumns = df.columns.values.tolist()
64+
subnets = parseSubnets(filename)
6465

6566
# Initialise empty TF string for each region
6667
for reg in ct.all_regions:
@@ -143,10 +144,44 @@ def create_terraform_exa_vmclusters(inputfile, outdir, prefix, config=DEFAULT_LO
143144
tempdict = {'exadata_infra_display_tf_name': display_tf_name}
144145

145146
if columnname == 'Client Subnet Name':
146-
columnvalue = commonTools.check_tf_variable(columnvalue)
147+
subnet_tf_name = columnvalue.strip()
148+
if ("ocid1.subnet.oc1" in subnet_tf_name):
149+
network_compartment_id = ""
150+
vcn_name = ""
151+
subnet_id = subnet_tf_name
152+
else:
153+
try:
154+
key = region, subnet_tf_name
155+
network_compartment_id = subnets.vcn_subnet_map[key][0]
156+
vcn_name = subnets.vcn_subnet_map[key][1]
157+
subnet_id = subnets.vcn_subnet_map[key][2]
158+
except Exception as e:
159+
print("Invalid Subnet Name specified for row " + str(
160+
i + 3) + ". It Doesnt exist in Subnets sheet. Exiting!!!")
161+
exit()
162+
163+
tempdict = {'network_compartment_id': commonTools.check_tf_variable(network_compartment_id),
164+
'vcn_name': vcn_name,
165+
'client_subnet_name': subnet_id}
147166

148167
if columnname == 'Backup Subnet Name':
149-
columnvalue = commonTools.check_tf_variable(columnvalue)
168+
subnet_tf_name = columnvalue.strip()
169+
if ("ocid1.subnet.oc1" in subnet_tf_name):
170+
network_compartment_id = ""
171+
vcn_name = ""
172+
subnet_id = subnet_tf_name
173+
else:
174+
try:
175+
key = region, subnet_tf_name
176+
network_compartment_id = subnets.vcn_subnet_map[key][0]
177+
vcn_name = subnets.vcn_subnet_map[key][1]
178+
subnet_id = subnets.vcn_subnet_map[key][2]
179+
except Exception as e:
180+
print("Invalid Subnet Name specified for row " + str(
181+
i + 3) + ". It Doesnt exist in Subnets sheet. Exiting!!!")
182+
exit()
183+
184+
tempdict = {'backup_subnet_name': subnet_id}
150185

151186
if columnname == 'NSGs':
152187
if columnvalue != '':

cd3_automation_toolkit/Database/export_dbsystems_vm_bm_nonGreenField.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ def export_dbsystems_vm_bm(inputfile, _outdir, _config, network_compartments=[])
222222

223223
with open(script_file, 'a') as importCommands[reg]:
224224
importCommands[reg].write('\n\nterraform plan\n')
225-
if "linux" in sys.platform:
226-
os.chmod(script_file, 0o755)
227225

228226
commonTools.write_to_cd3(values_for_column, cd3file, sheetName)
229227
print("Virtual Machine and Bare Metal DB Systems exported to CD3\n")

cd3_automation_toolkit/Database/export_exa_infra_nonGreenField.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ def export_exa_infra(inputfile, _outdir, _config, network_compartments=[]):
126126
for exa_infra in exa_infras.data:
127127
print_exa_infra(region, exa_infra,values_for_column, ntk_compartment_name)
128128

129-
if "linux" in sys.platform:
130-
os.chmod(script_file, 0o755)
131-
132129
commonTools.write_to_cd3(values_for_column, cd3file, sheetName)
133130

134131
print("Exadata Infra exported to CD3\n")

cd3_automation_toolkit/Database/export_exa_vmclusters_nonGreenField.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ def export_exa_vmclusters(inputfile, _outdir, _config, network_compartments=[]):
201201

202202
with open(script_file, 'a') as importCommands[reg]:
203203
importCommands[reg].write('\n\nterraform plan\n')
204-
if "linux" in sys.platform:
205-
os.chmod(script_file, 0o755)
206204

207205
commonTools.write_to_cd3(values_for_column, cd3file, sheetName)
208206

cd3_automation_toolkit/Database/templates/adb-template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ADB - tfvars
77
# Allowed Values:
88
# compartment_id and network_compartment_id can be the ocid or the name of the compartment hierarchy delimited by double hiphens "--"
9-
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Network-root-cpt--Network" where "Network-root-cpt" is the parent of "Network" compartment
9+
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Database--Prod" where "Database" is the parent of "Prod" compartment
1010
############################
1111

1212
adb = {

cd3_automation_toolkit/Database/templates/dbsystems-vm-bm-template

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Allowed Values:
88
# subnet_id and nsg_ids can be ocids or the key of subnets (map) and nsgs (map)
99
# compartment_id and network_compartment_id can be the ocid or the name of the compartment hierarchy delimited by double hiphens "--"
10-
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Network-root-cpt--Network" where "Network-root-cpt" is the parent of "Network" compartment
10+
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Database--Prod" where "Database" is the parent of "Prod" compartment
1111
# Sample import command for DBSystem-VM-BM:
1212
# terraform import "module.dbsystems-vm-bm[\"<<dbsystems_vm_bm terraform variable name>>\"].oci_database_db_system.database_db_system" <<dbsystem ocid>>
1313
############################
@@ -18,7 +18,9 @@ dbsystems_vm_bm = {
1818
availability_domain = {{ availability_domain }}
1919
compartment_id = "{{ compartment_name }}"
2020
shape = "{{ shape }}"
21-
subnet_id = "{{ subnet_name }}"
21+
network_compartment_id = "{{ network_compartment_id }}"
22+
vcn_name = "{{ vcn_name }}"
23+
subnet_id = "{{ subnet_id }}"
2224
hostname = "{{ hostname_prefix }}"
2325

2426
{% if cpu_core_count %}

cd3_automation_toolkit/Database/templates/exa-infra-template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ExaInfra - tfvars
77
# Allowed Values:
88
# compartment_id and network_compartment_id can be the ocid or the name of the compartment hierarchy delimited by double hiphens "--"
9-
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Network-root-cpt--Network" where "Network-root-cpt" is the parent of "Network" compartment
9+
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Database--Prod" where "Database" is the parent of "Prod" compartment
1010
# Sample import command for ExaInfra:
1111
# terraform import "module.exa-infra[\"<<exa_infra terraform variable name>>\"].oci_database_cloud_exadata_infrastructure.exa_infra" <<exainfra ocid>>
1212
############################

cd3_automation_toolkit/Database/templates/exa-vmclusters-template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Allowed Values:
88
# cluster_subnet_id, backup_subnet_id and exadata_infrastructure_id can be ocids or the key of subnets (map) and exa_infra (map) respectively
99
# compartment_id and network_compartment_id can be the ocid or the name of the compartment hierarchy delimited by double hiphens "--"
10-
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Network-root-cpt--Network" where "Network-root-cpt" is the parent of "Network" compartment
10+
# Example : compartment_id = "ocid1.compartment.oc1..aaaaaaaahwwiefb56epvdlzfic6ah6jy3xf3c" or compartment_id = "Database--Prod" where "Database" is the parent of "Prod" compartment
1111
# Sample import command for ExaVMClusters:
1212
# terraform import "module.exa-vmclusters[\"<<exa_vmclusters terraform variable name>>\"].oci_database_cloud_vm_cluster.exa_vmcluster" <<exavmcluster ocid>>
1313
############################
@@ -18,6 +18,8 @@ exa_vmclusters = {
1818
{{ vm_cluster_display_tf_name }} = {
1919
compartment_id = "{{ compartment_name }}"
2020
exadata_infrastructure_id= "{{ exadata_infra_display_tf_name }}"
21+
network_compartment_id = "{{ network_compartment_id }}"
22+
vcn_name = "{{ vcn_name }}"
2123
cluster_subnet_id = "{{ client_subnet_name }}"
2224
gi_version = "{{ oracle_grid_infrastructure_version }}"
2325
hostname = "{{ hostname_prefix }}"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python3
2+
3+
from .create_terraform_oke import create_terraform_oke
4+
from .export_oke_nonGreenField import export_oke

0 commit comments

Comments
 (0)