Grouping set of resources into a single TF state file
For Large Infrastructures, maintaining terraform files for all services (Network, Instances, LBaaS, Databases etc.,) within a single folder is not a viable option.
CD3 provides an option to choose between a single output directory for all services or separate directories for each service to store the generated Terraform files.
This option can be configured while connecting CD3 container to the OCI tenancy.
The parameter outdir_structure_file
in connectOCI.properties
, can be used to configure single outdirectory or separate outdirectories for each service.
By default, the toolkit is configured to use different out directories for different services.
Steps to customize directory names to be created for each OCI service -
-
Go to
/cd3user/oci_tools/cd3_automation_toolkit/connectOCI.properties
. Enter required config details.Make sure that outdir_structure_file is set to a pre-defined path of outdir_structure_file.properties. Refer to the screenshot below:
-
Under the same user-scripts folder, open
outdir_structure_file.properties
and modify the directory names if required. They are in the format:OCI_Service_Name=Directory_Name
Note
- Do not modify the OCI service Names specified on the left hand side.Modify the directory name specified on Right Hand Side only.
- Directory will be created for that service under <region> directory. Do not provide absolute path.
- To make any changes to the directory structure later, it is necessary to rerun the
createTenancyConfig.py
script from scratch. - It is mandatory to specify the directory name for each service.
Here, the network and nsg directories have been renamed to demo_network and demo_nsg respectively. The next steps to run the toolkit remain the same as specified in Greenfield workflow
-
Run
python createTenancyConfig.py connectOCI.properties
fromcd3_automation_toolkit
folder. This will create prefix folder as/cd3user/tenancies/<prefix>/
and configure a seperate directory for each service inside region folder subscribed to the tenancy. -
Go to
/cd3user/tenancies/<prefix>/<prefix>_setUpOCI.propertiesfile
and add the CD3 Excel path.Change to the below directory
cd /cd3user/oci_tools/cd3_automation_toolkit/
Run the script
python setUpCloud.py oci /cd3user/tenancies/<prefix>/<prefix>_setUpOCI.properties
Select required options. (Here,"Network", "nsg" options have been selected to verify the files under the "demo_network", "demo_nsg" folders)
auto.tfvars for the respective services are created.
-
Go to the region directory
/cd3user/tenancies/<prefix>/terraform_files/<region>/
. It is clear that all the service-specific folders have been created successfully. -
Navigate to the demo-network folder. All the auto.tfvars and tfstate files related to Network service can be seen within the demo_network folder. Terraform operations like terraform init, terraform plan, terraform apply etc., will be executed from within these folders.
Similarly for all the services, their respective auto.tfvars and tfstate files get grouped under their assigned directories. This makes it much easier to manage OCI resources using terraform for large-scale infrastructures.
Likewise, While doing an export from OCI to terraform, update the
connectOCI.properties
file with path tooutdir_structure_file.properties
similar to step-1 and then follow the steps to run the toolkit for Non-green field tenancies. With this, all the .sh files with import commands of a particular OCI service are grouped and can be easily managed.
Steps to use single out directory for all OCI services -
-
Go to
/cd3user/oci_tools/cd3_automation_toolkit/connectOCI.properties
. Enter required config details.Make sure that outdir_structure_file is set to empty value. Refer to the screenshot below:
-
Run
python createTenancyConfig.py connectOCI.properties
fromcd3_automation_toolkit
folder. This will create prefix folder as/cd3user/tenancies/<prefix>/
and tfvars/state file for each service inside the region folder subscribed for the region. -
Rest of the steps to run the toolkit remain the same.