Grouping set of resources into a single TF state file
The CD3 Automation Toolkit was previously built to generate all the output Terraform files within a designated region directory. OCI components like - Network, Instances, LBaaS, Databases etc., were maintained in a single tfstate file. This was not a viable option for tenancies requiring huge infrastructure.
Starting with the Automation Toolkit release v10.1, it is possible to select separate directories for each Oracle Cloud Infrastructure (OCI) service that is supported by the toolkit.
This can be configured while connecting CD3 container to the OCI tenancy.
A new parameter outdir_structure_file
has been introduced in tenancyconfig.properties
, which can be used to configure single outdir or different outdir 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/user-scripts/tenancyconfig.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 tenancyconfig.properties
from user-scripts 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 setUpOCI.py /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
tenancyconfig.properties
file with path tooutdir_structure_file.properties
similar to step1 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/user-scripts/tenancyconfig.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 tenancyconfig.properties
from user-scripts 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.