LAB 43 (Create instance through terraform and stack) - arunsinghchauhan38-arch/CLOUDARCHITECTDOC GitHub Wiki
Steps to Create Instance through terraform and stack
Step 1. Create instance in Oracle console
Now Click on Save as Stack
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
-
Name of the Stack :- teraform_server
-
Compartment :- Hub_compute_and_storage_compartment
-
Terraform version :- 1.5.x (This is a Latest version of stack)
In final Review page we check the details of stack and click on Create
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
Now we Download the Terraform configuration File in our local computer drive.
Downloaded file we unzip and open
We See file shows as Main.tf this is a Terraform file and its Decoded by .TF.
In terraform file we see the all the scripts for instance creation. with help of this script we will create the instance
Step 3. Modify script by OCI Code editor
Now Create a new file Name instance.tf
Next we copy the all the script and paste here
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
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.
Ones all the details filled than we go for next step
Step 4. Create Instance (VM) by Code Editor
First we open it in to the integrated Terminal
- Use command for initialization of terraform software
terraform init
- Use Command for Plan, for Showing the over all plan for instance creation
terraform plan
After verify all the plan with our requirement we will procced for the next step.
- Use command Apply, for Create instance
terraform apply
and press "Yes"
After perform this command our instance created by terraform
Now we try to log in to created server
We successfully login in to the newly created instance or server by terraform
Step 5. Destroy the Instance via Terraform
To Destroy the instance use command
terraform destroy
Next Press "yes"
Instance successfully destroyed.