Skip to content

LAB 43 (Create instance through terraform and stack)

arunsinghchauhan38-arch edited this page Jun 23, 2026 · 2 revisions

Steps to Create Instance through terraform and stack

Step 1. Create instance in Oracle console

image image image image image image image image

Now Click on Save as Stack

image

Step 2 Create Stack

In Stack everything by default set, so we don't want to change anything here. We press only next button here

Things to Check

  1. Name of the Stack :- teraform_server

  2. Compartment :- Hub_compute_and_storage_compartment

  3. Terraform version :- 1.5.x (This is a Latest version of stack)

image

In final Review page we check the details of stack and click on Create

image image

Important Note :- In Review Page a option available with check box Named Run apply. we can't click on this check box because if we click on it and click on create so its create instance quicky.

In this Lab we only want scripts from stacks for our instance so we avoid to click on it. we directly click on create button.

Our Stack Create Successfully

image

Now we Download the Terraform configuration File in our local computer drive.

image image

Downloaded file we unzip and open

We See file shows as Main.tf this is a Terraform file and its Decoded by .TF.

image

In terraform file we see the all the scripts for instance creation. with help of this script we will create the instance

image

Step 3. Modify script by OCI Code editor

image image

Now Create a new file Name instance.tf

image image

Next we copy the all the script and paste here

image image

After pasting script we edit the provider row with give details

provider "oci" {
    auth                = "APIKey" 
    tenancy_ocid        = "ocid1.tenancy.oc1..aaaaaaaae264lss2tpg5w3rc6ktkttm22tjyzy46tgfnwihjdaw7x5csbkea"
    user_ocid           = "ocid1.user.oc1..aaaaaaaapqcjvc574ck55obqyviqetxyx4xtoazcio2hwvl3ux7a55wqcrqa"
    fingerprint         = "35:b1:f1:67:e7:dc:ef:af:67:1e:5d:64:5d:c5:bd:25"
    private_key_path    = "priv.pem"
    region              = "us-ashburn-1"
}

for fingerprint, private key path and region we generate token and key from the console

image image image image image

After generate token & key from console. we fill the details in code editor and for private key we create a new file in code editor named priv.pem and paste the downloaded key here.

And in Private key Path mention the key name as **priv.pem.

image image

Ones all the details filled than we go for next step

image

Step 4. Create Instance (VM) by Code Editor

First we open it in to the integrated Terminal

image
  1. Use command for initialization of terraform software
terraform init
image
  1. Use Command for Plan, for Showing the over all plan for instance creation
terraform plan
image image image image

After verify all the plan with our requirement we will procced for the next step.

  1. Use command Apply, for Create instance
terraform apply

and press "Yes"

image

After perform this command our instance created by terraform

image

Now we try to log in to created server

We successfully login in to the newly created instance or server by terraform

image

Step 5. Destroy the Instance via Terraform

To Destroy the instance use command

terraform destroy

Next Press "yes"

image image image image

Instance successfully destroyed.

Clone this wiki locally