Skip to content

Lab :45 create compartment using modular approach

TanveeKhanDB edited this page Jul 14, 2026 · 12 revisions

Scenario: We have to create one compartment and two sub compartment in OCI with the help of Terracode by using modular approach. A modular Terraform approach is the recommended way to provision resources in Oracle Cloud Infrastructure (OCI) because it makes your code reusable, scalable, and easier to maintain. image

Steps to create compartment by terraform code with Modular approch

S1. I have created on tamplate as terra_compartment_tamplate

image

S2. Providing OCID of our teanancy where going to create compartment. image image

S3. Terraform plan is working fine

terraform plan
image image

S4. Succesfully creation of parent compartment which is Blinkit:

terraform apply
image image image image

S5.Creating two child compartment under Blinkit

Blinkit_compute_and_storage

Blinkit_networking

image

How to distroy any specific services in OCI by Terraform.

terraform destroy -target=module.<module_name>.<Resource_type>.<Resource_Name>
terraform destroy -target=module.parent_compartment.oci_identity_compartment.compartment1
image

Clone this wiki locally