Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Deploy Infrastructure using Terraform
Introduction
In this tutorial we will use pre-configured terraform scripts to deploy VCN, Subnet and Compute Instance. We will then delete all these infrastructure resources.
Estimated time: 30 minutes
Key points
- We recommend using Chrome or Edge as the browser.
- You will be asked to record some information during this workshop. We recommend that you paste the information into a text file when prompted.
Prerequisites
- OCI Training
- Familiarity with OCI console
- Overview of Networking
- Familiarity with Compartment
- Cloud Shell
Task 1: Access OCI Cloud Shell
-
From the OCI Console, click Cloud Shell to launch a cloud shell session.
Note: Ensure that the correct Compartment is selected under COMPARTMENT list.
-
Click the Profile icon, then click your tenancy. Click Copy and record your tenancy OCID for later use.
-
Click your region, then click Manage Regions. Copy your region identifier and record it for later use.
-
Click Identity & Security in the navigation menu, then click Compartments.
Click Copy and record your compartment OCID for later use.
Task 2: Configure Terraform
-
From the cloud shell use this command to download the Terraform sample code:
curl https://objectstorage.us-ashburn-1.oraclecloud.com/p/W7d4rKt71E8pOkTyB1ca5lbuerxDcyL0ZjuIMIRQ15-i-JW7KJOC6TMKSnD-_bZO/n/ociobenablement/b/lab/o/terraform_demo.zip -o terraform-demo.zip
-
Unzip the sample file using this command:
unzip terraform-demo.zip
-
Open the terraform.tfvars file using these commands:
cd terraform_demo
vi terraform.tfvars
-
Enter
i
to update the - tenancy_ocid, region, compartment_ocid variables with the values you recorded in the Access the OCI Shell task. -
Enter
:wq!
to save the file and exit. -
Initialize terraform using this command:
terraform init
A successful initialization message is returned:
-
View the deployment plan of what will be configured in OCI using this command:
terraform plan
-
Apply the plan to create the infrastructure using this command:
terraform apply
Note: Enter ‘yes’ when prompted.
The script takes some time to execute. You can switch to the OCI console and observe the creation of the VCN, Compute instance. You will see below messege when apply is completed.
-
When done, destroy the infrastructure that you created using this command:
terraform destroy
Note: Enter ‘yes’ when prompted.
You can switch to the OCI console and observe deletion of VCN, Compute instance. You will see below messege when destroy is completed.
Acknowledgements
- Author - Flavio Pereira, Larry Beausoleil
- Adapted by - Yaisah Granillo, Cloud Solution Engineer
- Contributor - Jaden McElvey, Technical Lead - Oracle LiveLabs Intern
- Last Updated By/Date - Kamryn Vinson, August 2020
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Automate Oracle Cloud Infrastructure resource provisioning using Terraform
F46710-02
November 2021
Copyright © 2021, Oracle and/or its affiliates.