{"id":2473,"date":"2025-10-14T20:55:21","date_gmt":"2025-10-14T20:55:21","guid":{"rendered":"https:\/\/www.cosmicro.com.au\/?p=2473"},"modified":"2025-10-15T10:18:07","modified_gmt":"2025-10-15T10:18:07","slug":"infrastructure-oracle-technology-terraform","status":"publish","type":"post","link":"https:\/\/www.cosmicro.com.au\/?p=2473","title":{"rendered":"Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1"},"content":{"rendered":"\n<p class=\"has-medium-font-size\">Overview<\/p>\n\n\n\n<p id=\"ember530\">This tutorial shows how to set up Terraform to manage Oracle Cloud Infrastructure (OCI), configure the OCI CLI on macOS and Windows, and create an OCI compartment with Terraform. It includes sample commands, Terraform code snippets, configuration tips, and suggested places where you would add graphical snapshots in your documentation or blog. References to official OCI and Terraform guides are included for each major step <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/API\/SDKDocs\/cliinstall.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/dev\/terraform\/tutorials\/tf-provider.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/dev\/terraform\/tutorials\/tf-compartment.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/resources\/identity_compartment\">Terraform Registry<\/a> <a href=\"https:\/\/developer.hashicorp.com\/terraform\/tutorials\/oci-get-started\">HashiCorp Developer<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p id=\"ember531\">Terraform is a powerful Infrastructure as Code (IaC) tool that allows you to define and provision cloud resources in a declarative way. This guide will walk you through setting up Terraform with Oracle Cloud Infrastructure (OCI), covering the OCI CLI configuration on both Mac and Windows, creating OCI compartments, and demonstrating some practical use cases.<\/p>\n\n\n\n<p id=\"ember532\"><strong>Prerequisites<\/strong><\/p>\n\n\n\n<p id=\"ember533\">Before you begin, ensure you have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Oracle Cloud Infrastructure (OCI) account.<\/li>\n\n\n\n<li>Basic understanding of command-line interfaces.<\/li>\n\n\n\n<li>Basic understanding of cloud concepts.<\/li>\n<\/ul>\n\n\n\n<p id=\"ember535\"><strong>Step 1: Install and Configure the OCI Command Line Interface (CLI)<\/strong><\/p>\n\n\n\n<p id=\"ember536\">The OCI CLI is essential for interacting with OCI resources from your local machine, and Terraform will use its configuration to authenticate.<\/p>\n\n\n\n<p id=\"ember537\"><strong>1.1 Install OCI CLI on Mac<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Open Terminal:<\/strong> You can find Terminal in Applications > Utilities.<\/li>\n\n\n\n<li><strong>Download and Run the Install Script:<\/strong> OCI provides a convenient install script. Run the following command:<\/li>\n<\/ol>\n\n\n\n<p id=\"ember539\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash -c \"$(curl -L https:\/\/raw.githubusercontent.com\/oracle\/oci-cli\/master\/scripts\/install\/install.sh)\"<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Follow the Prompts:<\/strong> The script will ask you for the installation location, Python executable, and whether to add the CLI to your PATH. It&#8217;s generally recommended to accept the default options unless you have specific requirements.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ\" alt=\"Article content\"\/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Verify Installation:<\/strong> Once installed, open a new terminal session and run:<\/li>\n<\/ol>\n\n\n\n<p id=\"ember543\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>oci --version<\/code><\/code><\/pre>\n\n\n\n<p id=\"ember544\">This should display the installed OCI CLI version.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>3.62.0<\/code><\/code><\/pre>\n\n\n\n<p id=\"ember545\"><strong>1.2 Install OCI CLI on Windows<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Download the Installer:<\/strong> Go to the official OCI CLI documentation page or directly download the Windows installer <a href=\"https:\/\/github.com\/oracle\/oci-cli\/releases\/tag\/v3.68.0\">https:\/\/github.com\/oracle\/oci-cli\/releases\/tag\/v3.68.0<\/a> Look for the &#8220;Installer for Windows (64-bit)&#8221; link.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEUYVTwqR47UQ\/article-inline_image-shrink_1000_1488\/B56ZniOdp3KIAU-\/0\/1760437067077?e=1763596800&amp;v=beta&amp;t=eu0bBToEkSeCnTLyACY6QamKXd0OGmYdXa3b2tV7LTw\" alt=\"Article content\"\/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Run the Installer:<\/strong> Execute the downloaded .msi file. The installer will guide you through the process.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEuhVicpGmwiA\/article-inline_image-shrink_1500_2232\/B56ZniSfo5IsAU-\/0\/1760438123535?e=1763596800&amp;v=beta&amp;t=hg5BkKRdf7pE7XHGmS0nMVPS0JAb0zEBsrMMtv7chkg\" alt=\"Article content\"\/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Accept Defaults:<\/strong> You can typically accept the default installation paths. Ensure &#8220;Add OCI CLI to PATH&#8221; is checked.<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Verify Installation:<\/strong> Open a new Command Prompt or PowerShell window and run:<\/li>\n<\/ol>\n\n\n\n<p id=\"ember554\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>oci --version<\/code><\/code><\/pre>\n\n\n\n<p id=\"ember555\">You should see the installed OCI CLI version.<\/p>\n\n\n\n<p id=\"ember556\"><strong>1.3 Configure OCI CLI<\/strong><\/p>\n\n\n\n<p id=\"ember557\">After installation, you need to configure the CLI with your OCI user credentials.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Run oci setup config:<\/strong> In your terminal (Mac) or Command Prompt\/PowerShell (Windows), run:<\/li>\n<\/ol>\n\n\n\n<p id=\"ember559\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>oci setup config<\/code><\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Provide Information:<\/strong> The utility will prompt you for the following: <strong>User OCID:<\/strong> You can find this in the OCI Console under <strong>Identity &amp; Security > Users<\/strong>. Click on your user and copy the OCID. <strong>Tenancy OCID:<\/strong> You can find this in the OCI Console under <strong>Tenancy Details<\/strong> (click on the hamburger menu at the top left, then<strong> Governance &amp; Administration > Tenancy Details<\/strong>). <strong>Region:<\/strong> Your OCI home region (e.g., ap-melbourne-1 default, which will create a new key pair for you.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQE9M-0DtlX2QQ\/article-inline_image-shrink_1000_1488\/B56ZniPzl1IsAU-\/0\/1760437419132?e=1763596800&amp;v=beta&amp;t=6qiNenkqiLlxO9qX6DG1KZZvXUO9yILnk-X-Gg20nQA\" alt=\"Article content\"\/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Upload Public Key to OCI Console:<\/strong> The oci setup config command creates a private key (oci_api_key.pem) and a public key (oci_api_key_public.pem). You need to upload the content of oci_api_key_public.pem to your OCI user. Open oci_api_key_public.pem with a text editor and copy its entire content. In the OCI Console, navigate to <strong>Identity &amp; Security > Users<\/strong>. Click on your user, then click &#8220;<strong>API Keys<\/strong>&#8221; on the left. Click &#8220;<strong>Add API Key,<\/strong>&#8221; choose &#8220;<strong>Paste Public Key,<\/strong>&#8221; and paste the content.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQGn6LGa6szVIA\/article-inline_image-shrink_1500_2232\/B56ZniR25HI8AU-\/0\/1760437957939?e=1763596800&amp;v=beta&amp;t=FgC9pzUqeQRiFTy398dhIbK5fYQLTV9bxMEPZDFsTv0\" alt=\"Article content\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQFSIjsSzIj2BA\/article-inline_image-shrink_1500_2232\/B56ZniR7N1KMAU-\/0\/1760437976356?e=1763596800&amp;v=beta&amp;t=uFV0EsG8zpSwKclLpIj7Dnd5N0YjhW6nvLXm3WXPYK0\" alt=\"Article content\"\/><\/figure>\n\n\n\n<p id=\"ember565\"><strong>Step 2: Install Terraform<\/strong><\/p>\n\n\n\n<p id=\"ember566\">Now that your OCI CLI is configured, let&#8217;s install Terraform.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Download Terraform:<\/strong> Go to the official Terraform downloads page: <a href=\"https:\/\/www.terraform.io\/downloads\">https:\/\/www.terraform.io\/downloads<\/a>.<\/li>\n\n\n\n<li><strong>Choose Your Operating System:<\/strong> Download the appropriate package for Mac (amd64 or arm64) or Windows (amd64).<\/li>\n\n\n\n<li><strong>Install Terraform:<\/strong> <strong>Mac:<\/strong> Unzip the downloaded package. Move the terraform executable to a directory in your PATH (e.g., \/usr\/local\/bin). <strong>Windows:<\/strong> Unzip the downloaded package. Create a new folder (e.g., C:\\terraform) and place the terraform.exe file there. Then, add this folder to your system&#8217;s PATH environment variable.<\/li>\n\n\n\n<li><strong>Verify Installation:<\/strong> Open a new terminal or Command Prompt and run:<\/li>\n<\/ol>\n\n\n\n<p id=\"ember568\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>terraform --version<\/code><\/code><\/pre>\n\n\n\n<p id=\"ember569\">This should display the installed Terraform version<\/p>\n\n\n\n<p id=\"ember570\">Reference: Quickstart and CLI config pages <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/API\/SDKDocs\/cliinstall.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/API\/SDKDocs\/cliconfigure.htm\">docs.oracle.com<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember571\">3. Prepare API keys and SSH keys for Terraform authentication<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Generate an RSA key pair for API signing (example on macOS\/Linux): \n<code>mkdir -p ~\/.oci openssl genrsa -out ~\/.oci\/oci_api_key.pem 2048 openssl rsa -pubout -in ~\/.oci\/oci_api_key.pem -out ~\/.oci\/oci_api_key_public.pem<\/code><\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Upload the <strong>public<\/strong> key in the OCI Console under your user (<strong>User \u2192 API Keys \u2192 Add Public Key<\/strong>) or use the CLI to upload. Note the key fingerprint added to your user entry.<\/li>\n\n\n\n<li>Ensure the private key file has restrictive permissions:<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEHvt8WQHp8Dw\/article-inline_image-shrink_1500_2232\/B56ZniSuNlKMAU-\/0\/1760438185294?e=1763596800&amp;v=beta&amp;t=1DPcmZarLvBOjUmSV82h2E3zD22jwaM6xuVQetlNfzQ\" alt=\"Article content\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><code>chmod 600 ~\/.oci\/oci_api_key.pem<\/code><\/code><\/pre>\n\n\n\n<p id=\"ember574\">OCI Console user API Keys page showing uploaded public key and fingerprint]<\/p>\n\n\n\n<p id=\"ember575\">Guidance: The API key links your CLI\/Terraform sessions to your OCI user and is required for provider authentication <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/dev\/terraform\/tutorials\/tf-provider.htm\">docs.oracle.com<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember576\">4. Install Terraform and OCI Provider<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install Terraform (macOS Homebrew or Windows Chocolatey): macOS: <strong>brew install terraform <\/strong>Windows (Chocolatey): <strong>choco install terraform<\/strong><\/li>\n\n\n\n<li>Create a Terraform working directory, e.g., ~\/tf-oci-compartment. Create a versions.tf to pin Terraform and provider versions:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code><code>terraform {\n  required_version = \">= 1.5.0\"\n  required_providers {\n    oci = {\n      source  = \"oracle\/oci\"\n      version = \">= 7.0.0\"\n    }\n  }\n} <\/code><\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Initialize Terraform in the directory:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code><code>terraform init <\/code><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>terraform init output showing OCI provider download and initialization<\/li>\n<\/ul>\n\n\n\n<p id=\"ember580\">Reference: HashiCorp Terraform OCI tutorials and Oracle provider docs <a href=\"https:\/\/developer.hashicorp.com\/terraform\/tutorials\/oci-get-started\">HashiCorp Developer<\/a> <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/guides\/tutorials\">Terraform Registry<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember581\">5. Configure Terraform to use OCI credentials<\/h3>\n\n\n\n<p id=\"ember582\">Option A \u2014 Use environment variables (suitable for CI\/CD and temporary sessions):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>export OCI_TENANCY=&lt;tenancy_ocid>\nexport OCI_USER=&lt;user_ocid>\nexport OCI_FINGERPRINT=&lt;api_key_fingerprint>\nexport OCI_KEY_FILE=~\/.oci\/oci_api_key.pem\nexport OCI_REGION=us-ashburn-1 <\/code><\/code><\/pre>\n\n\n\n<p id=\"ember583\">Option B \u2014 Use a provider block referencing the CLI config profile (recommended when ~\/.oci\/config exists):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>provider \"oci\" {\n  tenancy_ocid     = var.tenancy_ocid\n  user_ocid        = var.user_ocid\n  fingerprint      = var.fingerprint\n  private_key_path = var.private_key_path\n  region           = var.region\n} <\/code><\/code><\/pre>\n\n\n\n<p id=\"ember584\">Define variables in variables.tf and sensitive values in terraform.tfvars or environment variables for security. Confirm provider setup by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>terraform plan <\/code><\/pre>\n\n\n\n<p id=\"ember585\">terraform plan output showing provider configuration OK<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember586\">6. Terraform example: Create an OCI Compartment<\/h3>\n\n\n\n<p id=\"ember587\">Create compartment.tf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>resource \"oci_identity_compartment\" \"example_compartment\" {\n  name        = \"demo-compartment\"\n  description = \"Terraform-managed compartment for demos\"\n  compartment_id = var.tenancy_ocid\n  enable_delete  = true\n  freeform_tags = {\n    created_by = \"terraform\"\n    project    = \"demo\"\n  }\n} <\/code><\/pre>\n\n\n\n<p id=\"ember588\">Create outputs.tf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>output \"compartment_ocid\" {\n  value = oci_identity_compartment.example_compartment.id\n} <\/code><\/pre>\n\n\n\n<p id=\"ember589\">Workflow:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>terraform init (if not done).<\/li>\n\n\n\n<li>terraform fmt to format files.<\/li>\n\n\n\n<li>terraform validate.<\/li>\n\n\n\n<li>terraform plan -out=tfplan.<\/li>\n\n\n\n<li>terraform apply &#8220;tfplan&#8221;.<\/li>\n<\/ol>\n\n\n\n<p id=\"ember591\">Notes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>By default, Terraform will not delete compartments unless enable_delete = true is set and the compartment is empty <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/resources\/identity_compartment\">Terraform Registry<\/a>.<\/li>\n\n\n\n<li>If a compartment with the same name exists and is unmanaged, provider behaviour may import or update it depending on configuration; exercise caution when multiple configs manage shared compartments <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/resources\/identity_compartment\">Terraform Registry<\/a>.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>terraform apply confirming creation and output showing compartment_ocid]<\/li>\n<\/ul>\n\n\n\n<p id=\"ember594\">Reference: Create a Compartment tutorial and provider resource docs <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/dev\/terraform\/tutorials\/tf-compartment.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/resources\/identity_compartment\">Terraform Registry<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember595\">7. Use cases and examples<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Single-tenant dev environment:<\/li>\n\n\n\n<li>Automated environment provisioning:<\/li>\n\n\n\n<li>Policy-driven multi-account models:<\/li>\n\n\n\n<li>Reusable module example (module skeleton):<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code># modules\/compartment\/main.tf\nresource \"oci_identity_compartment\" \"this\" {\n  name           = var.name\n  description    = var.description\n  compartment_id = var.parent_compartment_id\n  enable_delete  = var.enable_delete\n  freeform_tags  = var.tags\n}\n\n# modules\/compartment\/variables.tf\nvariable \"name\" {}\nvariable \"description\" { default = \"\" }\nvariable \"parent_compartment_id\" {}\nvariable \"enable_delete\" { default = false }\nvariable \"tags\" { default = {} } <\/code><\/pre>\n\n\n\n<p id=\"ember597\">Instantiate module:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>module \"project_compartment\" {\n  source = \".\/modules\/compartment\"\n  name = \"project-x\"\n  parent_compartment_id = var.tenancy_ocid\n  enable_delete = true\n  tags = { owner = \"team-x\" }\n} <\/code><\/pre>\n\n\n\n<p id=\"ember598\">Recommendation: Keep compartments small and lifecycle simple; use modules for repeatability and guardrails.<\/p>\n\n\n\n<p id=\"ember599\">References: Simple infrastructure tutorial and Terraform Registry examples <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/dev\/terraform\/tutorials\/tf-simple-infrastructure.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/guides\/tutorials\">Terraform Registry<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember600\">8. Troubleshooting and best practices<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>IAM permission errors: ensure the user\u2019s policy grants identity and compartment creation privileges. Test with the OCI Console or CLI before running Terraform.<\/li>\n\n\n\n<li>Shared compartments: avoid multiple Terraform states managing the same compartment name; prefer explicit OCIDs when several teams interact. The provider can import existing compartments but this can create drift or conflicts <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/resources\/identity_compartment\">Terraform Registry<\/a>.<\/li>\n\n\n\n<li>State management: use a remote state backend (e.g., Terraform Cloud, OCI Object Storage with locking) for team collaboration.<\/li>\n\n\n\n<li>Secrets handling: never store private keys or secrets in plain text in VCS; use secret managers or CI\/CD secret stores.<\/li>\n<\/ul>\n\n\n\n<p id=\"ember602\">Reference: Provider and tutorial guidance on behavior and best practices <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/resources\/identity_compartment\">Terraform Registry<\/a> <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/dev\/terraform\/tutorials\/tf-provider.htm\">docs.oracle.com<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember603\">9. Suggested graphical snapshots to include in your article<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>OCI Console: User \u2192 API Keys page showing uploaded public key and fingerprint (for API auth).<\/li>\n\n\n\n<li>macOS terminal: oci setup config interactive prompts and ~\/.oci\/config content.<\/li>\n\n\n\n<li>Windows PowerShell: oci setup config and %USERPROFILE%.oci\\config.<\/li>\n\n\n\n<li>Terraform directory: file tree showing versions.tf, provider.tf, compartment.tf.<\/li>\n\n\n\n<li>terraform plan and terraform apply outputs with created resource OCID.<\/li>\n\n\n\n<li>OCI Console: Compartments list showing the newly created compartment and tags.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember605\">Quick reference commands<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install OCI CLI (macOS): brew install oci-cli <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/API\/SDKDocs\/cliinstall.htm\">docs.oracle.com<\/a>.<\/li>\n\n\n\n<li>Setup OCI CLI: oci setup config <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/API\/SDKDocs\/cliinstall.htm\">docs.oracle.com<\/a>.<\/li>\n\n\n\n<li>Terraform init: terraform init <a href=\"https:\/\/developer.hashicorp.com\/terraform\/tutorials\/oci-get-started\">HashiCorp Developer<\/a>.<\/li>\n\n\n\n<li>Create plan: terraform plan -out=tfplan.<\/li>\n\n\n\n<li>Apply plan: terraform apply &#8220;tfplan&#8221;.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember607\">Final notes<\/h3>\n\n\n\n<p id=\"ember608\">This article is based followed official OCI and Terraform guidance: OCI CLI quickstart and configuration, Set Up OCI Terraform, and Create a Compartment tutorials, and provider documentation for the oci_identity_compartment resource <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/API\/SDKDocs\/cliinstall.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/dev\/terraform\/tutorials\/tf-provider.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/docs.oracle.com\/en-us\/iaas\/Content\/dev\/terraform\/tutorials\/tf-compartment.htm\">docs.oracle.com<\/a> <a href=\"https:\/\/registry.terraform.io\/providers\/oracle\/oci\/latest\/docs\/resources\/identity_compartment\">Terraform Registry<\/a> <a href=\"https:\/\/developer.hashicorp.com\/terraform\/tutorials\/oci-get-started\">HashiCorp Developer<\/a>. Use modules and remote state early, and keep IAM and key management secure when automating OCI with Terraform.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">If you like my work, please provide feedback, support and reach out if you need further support<\/p>\n\n\n\n<p>Author: Zak Khan <\/p>\n\n\n\n<p>Email: zak@cosmicro.com.au<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview This tutorial shows how to set up Terraform to manage Oracle Cloud Infrastructure (OCI), configure the OCI CLI on macOS and Windows, and create an OCI compartment with Terraform. It includes sample commands, Terraform code snippets, configuration tips, and suggested places where you would add graphical snapshots in your documentation or blog. References to [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,93],"tags":[92,90,27,91],"class_list":["post-2473","post","type-post","status-publish","format-standard","hentry","category-quick-tips","category-infrastructure-oracle-technology-terraformcyber-security","tag-infrastructure","tag-oracle","tag-technology","tag-terraform"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1 -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cosmicro.com.au\/?p=2473\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1 -\" \/>\n<meta property=\"og:description\" content=\"Overview This tutorial shows how to set up Terraform to manage Oracle Cloud Infrastructure (OCI), configure the OCI CLI on macOS and Windows, and create an OCI compartment with Terraform. It includes sample commands, Terraform code snippets, configuration tips, and suggested places where you would add graphical snapshots in your documentation or blog. References to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cosmicro.com.au\/?p=2473\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-14T20:55:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-15T10:18:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ\" \/>\n<meta name=\"author\" content=\"Zak Khan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Zak Khan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cosmicro.com.au\/?p=2473\",\"url\":\"https:\/\/www.cosmicro.com.au\/?p=2473\",\"name\":\"Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1 -\",\"isPartOf\":{\"@id\":\"https:\/\/www.cosmicro.com.au\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.cosmicro.com.au\/?p=2473#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.cosmicro.com.au\/?p=2473#primaryimage\"},\"thumbnailUrl\":\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ\",\"datePublished\":\"2025-10-14T20:55:21+00:00\",\"dateModified\":\"2025-10-15T10:18:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.cosmicro.com.au\/#\/schema\/person\/064db9077c05a06426760798324e1e78\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.cosmicro.com.au\/?p=2473#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cosmicro.com.au\/?p=2473\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.cosmicro.com.au\/?p=2473#primaryimage\",\"url\":\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ\",\"contentUrl\":\"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.cosmicro.com.au\/?p=2473#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.cosmicro.com.au\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cosmicro.com.au\/#website\",\"url\":\"https:\/\/www.cosmicro.com.au\/\",\"name\":\"cosmicro.com.au\",\"description\":\"Cosmicro - Driven by Virtues\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.cosmicro.com.au\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.cosmicro.com.au\/#\/schema\/person\/064db9077c05a06426760798324e1e78\",\"name\":\"Zak Khan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.cosmicro.com.au\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/da2978c85a45f64bd17a043990c1a9b755297bc0deb4fda6257118cd3bfdf868?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/da2978c85a45f64bd17a043990c1a9b755297bc0deb4fda6257118cd3bfdf868?s=96&d=mm&r=g\",\"caption\":\"Zak Khan\"},\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/zahidkhan\/\"],\"url\":\"https:\/\/www.cosmicro.com.au\/?author=4\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1 -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cosmicro.com.au\/?p=2473","og_locale":"en_US","og_type":"article","og_title":"Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1 -","og_description":"Overview This tutorial shows how to set up Terraform to manage Oracle Cloud Infrastructure (OCI), configure the OCI CLI on macOS and Windows, and create an OCI compartment with Terraform. It includes sample commands, Terraform code snippets, configuration tips, and suggested places where you would add graphical snapshots in your documentation or blog. References to [&hellip;]","og_url":"https:\/\/www.cosmicro.com.au\/?p=2473","article_published_time":"2025-10-14T20:55:21+00:00","article_modified_time":"2025-10-15T10:18:07+00:00","og_image":[{"url":"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ","type":"","width":"","height":""}],"author":"Zak Khan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Zak Khan","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.cosmicro.com.au\/?p=2473","url":"https:\/\/www.cosmicro.com.au\/?p=2473","name":"Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1 -","isPartOf":{"@id":"https:\/\/www.cosmicro.com.au\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cosmicro.com.au\/?p=2473#primaryimage"},"image":{"@id":"https:\/\/www.cosmicro.com.au\/?p=2473#primaryimage"},"thumbnailUrl":"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ","datePublished":"2025-10-14T20:55:21+00:00","dateModified":"2025-10-15T10:18:07+00:00","author":{"@id":"https:\/\/www.cosmicro.com.au\/#\/schema\/person\/064db9077c05a06426760798324e1e78"},"breadcrumb":{"@id":"https:\/\/www.cosmicro.com.au\/?p=2473#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cosmicro.com.au\/?p=2473"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cosmicro.com.au\/?p=2473#primaryimage","url":"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ","contentUrl":"https:\/\/media.licdn.com\/dms\/image\/v2\/D5612AQEBbiBKXUZ-Aw\/article-inline_image-shrink_1500_2232\/B56ZniN23KKUAU-\/0\/1760436909063?e=1763596800&amp;v=beta&amp;t=boOD9atG_1ODEGoOKe6p7VvluULjkIgOkprBCsqtEgQ"},{"@type":"BreadcrumbList","@id":"https:\/\/www.cosmicro.com.au\/?p=2473#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cosmicro.com.au\/"},{"@type":"ListItem","position":2,"name":"Terraform to manage Oracle Cloud Infrastructure (OCI) Part-1"}]},{"@type":"WebSite","@id":"https:\/\/www.cosmicro.com.au\/#website","url":"https:\/\/www.cosmicro.com.au\/","name":"cosmicro.com.au","description":"Cosmicro - Driven by Virtues","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cosmicro.com.au\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.cosmicro.com.au\/#\/schema\/person\/064db9077c05a06426760798324e1e78","name":"Zak Khan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cosmicro.com.au\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/da2978c85a45f64bd17a043990c1a9b755297bc0deb4fda6257118cd3bfdf868?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/da2978c85a45f64bd17a043990c1a9b755297bc0deb4fda6257118cd3bfdf868?s=96&d=mm&r=g","caption":"Zak Khan"},"sameAs":["https:\/\/www.linkedin.com\/in\/zahidkhan\/"],"url":"https:\/\/www.cosmicro.com.au\/?author=4"}]}},"_links":{"self":[{"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=\/wp\/v2\/posts\/2473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2473"}],"version-history":[{"count":4,"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=\/wp\/v2\/posts\/2473\/revisions"}],"predecessor-version":[{"id":2497,"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=\/wp\/v2\/posts\/2473\/revisions\/2497"}],"wp:attachment":[{"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cosmicro.com.au\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}