Back to Blog
Automating Infrastructure: OCI CLI and Terraform for Beginners

Automating Infrastructure: OCI CLI and Terraform for Beginners

   Mariusz Antonik    Automation    2 min read    25 views

Introduction

Manual setup is fine for a single instance — but when you’re managing multiple networks, compute nodes, and databases, automation becomes essential. OCI provides powerful tools like the Command Line Interface (CLI) and Terraform to simplify and replicate deployments.

OCI CLI – Your Command-Line Control Center

The OCI CLI lets you interact with your environment using scripts or terminal commands.

Installation

 
pip install oci-cli oci setup config

Example Commands

 
oci compute instance list oci network vcn create --compartment-id <id> --display-name DemoVCN

Use CLI for scripting, monitoring, and quick automation tasks.

Terraform – Infrastructure as Code

Terraform automates full infrastructure builds using declarative templates.
A simple example:

 
provider "oci" { tenancy_ocid = "<tenancy>" user_ocid = "<user>" region = "us-ashburn-1" } resource "oci_core_vcn" "vcn" { compartment_id = "<compartment>" display_name = "DemoVCN" cidr_block = "10.0.0.0/16" }

Run:

 
terraform init terraform apply

Your network appears automatically.

Automation Best Practices

  • Keep your Terraform scripts in Git for version control

  • Use variables.tf for environment customization

  • Encrypt credentials with Vault or OCI secrets

  • Validate templates before deployment

Conclusion

Using OCI CLI and Terraform, you can deploy complex architectures consistently and repeatably — no manual clicks required.