DEV Community

Cover image for How to create an OCI bucket using Terraform
Faris Durrani
Faris Durrani

Posted on

How to create an OCI bucket using Terraform

A simple tutorial to create a bucket in Oracle Cloud using Terraform

1. Set up the OCI Configuration using API Keys

Follow the steps in Setting up the OCI Configuration File using API Keys

2. Install Terraform CLI

On Mac, you can install the CLI using Homebrew: brew install oci-cli

Verify installation using oci -v in the terminal. For other OSes, see Install Terraform.

3. Write the following Terraform code

terraform {
  required_providers {
    oci = {
      source  = "oracle/oci"
      version = ">= 7.0.0"
    }
  }
  required_version = ">=1.12"
}

provider "oci" {
  region              = "us-ashburn-1"
  config_file_profile = "DEFAULT"
}

resource "oci_objectstorage_bucket" "test_bucket" {
  #Required
  compartment_id = "ocid1.tenancy.oc1..aaaaaaaanwazgsy3nui2mz8wttfh26k7ra6xiazgsy3nui2mz8wttfh26k7ra6"
  name           = "test-bucket"
  namespace      = "idpugazgsy3"
}
Enter fullscreen mode Exit fullscreen mode

More info about the Terraform resource: oci_objectstorage_bucket

We create the OCI bucket in the root tenancy compartment ID. You may get your tenancy ID and the Object storage namespace under your Tenancy details under Profile once logged into cloud.oracle.com.

Get tenancy details

4. Apply the terraform plan

Run:

terraform init && terraform apply
Enter fullscreen mode Exit fullscreen mode

Apply terraform plan

new bucket

Safe harbor statement

The information provided on this channel/article/story is solely intended for informational purposes and cannot be used as a part of any contractual agreement. The content does not guarantee the delivery of any material, code, or functionality, and should not be the sole basis for making purchasing decisions. The postings on this site are my own and do not necessarily reflect the views or work of Oracle or Mythics, LLC.

This work is licensed under a Creative Commons Attribution 4.0 International License.

Top comments (0)