Getting Started

Terraform is "infrastructure-as-code" software that allows you to define your Oracle Cloud Infrastructure (OCI) resources in files that you can persist, version, and share. These files describe the steps required to provision your infrastructure and maintain its desired state:

Resources can create OCI infrastructure objects such as virtual cloud networks or compute instances. Your first application of the configuration creates the objects, and subsequent applications can update or delete them.

Data sources represent read-only views of your existing OCI infrastructure.

Variables represent parameters for Terraform.

Caution

Terraform state files contain all resource attributes that are specified as part of configuration files. If you manage any sensitive data with Terraform, like database or user passwords or instance private keys, you should treat the state file itself as sensitive data. See Storing Sensitive Data for more information.

Example Usage

Terraform executes the steps and builds out the infrastructure that you describe in configuration files. When the configuration below is applied, for example, Terraform connects to your tenancy and retrieves a list of its availability domains. Because there are no resources defined in this configuration, no infrastructure is created or modified.

# Configure the OCI provider with an API Key
# tenancy_ocid is the compartment OCID for the root compartment
provider "oci" {
  tenancy_ocid = var.tenancy_ocid
  user_ocid = var.user_ocid
  fingerprint = var.fingerprint
  private_key_path = var.private_key_path
  region = var.region
}

# Get a list of Availability Domains
data "oci_identity_availability_domains" "ads" {
  compartment_id = var.tenancy_ocid
}

# Output the result
output "show-ads" {
  value = data.oci_identity_availability_domains.ads.availability_domains
}

See Authoring Configurations for more detailed information about Terraform configuration requirements.