Lab :44 create instance using modular approach - TanveeKhanDB/OCI GitHub Wiki
Non modular approach
Non-modular: In this technique all .tf files live flat in one folder — simple to start, but hard to reuse across environments.
Modular approach:
Modular: Resources are packaged into a reusable modules/dev/ folder called from root main.tf — change variables, not code, to deploy to staging or prod.
Requierment:
We needs to prepare a tamplate which can be used by different teams such as Dev,Test, Prod,UAT to create comupte instance as per their need just passing their requirement to the tamplate
Steps to perform modular approch in OCI:
S1: Open code editor in OCI.
S2: Create one tamplate which can be used by all the dept terra_compute_template which has four files
1 provider.tf
It contains all the OCI related information.
- provider "oci"
- auth
- tenancy_ocid
- user_ocid
- fingerprint
- private_key_path
- region
2 main.tf
It has all the definition for instance creation.
3 priavate_key.pem
It has key details for securily connecting with OCI.
4 variable.tf
It contains all the variable definition which passed the req details to tamplate received by differernt dept such as dev,uat
S3. Created one folder TK which contain all the instance form diffrent environment dev,test,prod,UAT now under which 04 more dircory has been created.
S4. Dev/Instance.tf: It contains module which has all the core infomation for isntance such as instance name, processing unit and memory.
S5. Dev/provider.tf: It contain the OCI related information for Dev environment.
S6. Creating instance for Dev department:
terraform plan
terraform apply
S7.Finallay insatnce has been created:
S8. Destroying the Dev instance:
terrraform destroy
Note: we can create multiple instance with respect to diff deparatment such as UAT, Prod,testing following the same logic.