Getting Started with the Terraform Provider
Learn about Terraform software and the OCI Terraform provider.
Terraform is "infrastructure-as-code" software that lets you define OCI resources in files that you can persist, version, and share. These files describe the steps required to provision infrastructure and maintain its state:
- Resources create OCI infrastructure objects, such as virtual cloud networks or compute instances. The first application of the configuration creates the objects, and later applications update or delete them.
- Data sources represent read-only views of existing OCI infrastructure.
- Variables represent parameters for Terraform.
Terraform state files contain all resource attributes that are specified as part of configuration files. If you manage any sensitive data with Terraform, such as database or user passwords or instance private keys, treat the state file itself as sensitive data. For more information, see Storing Sensitive Data.
First Steps
To get started, you can visit our Terraform provider tutorials for detailed walkthroughs and examples, or see the following pages for steps to install and configure the OCI Terraform provider:
Example Usage
Terraform executes the steps and builds out the infrastructure that you describe in configuration files.
For example, when the following configuration is applied, Terraform connects to your tenancy and retrieves a list of its availability domains. Because no resources are 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
}
For more information about Terraform configuration requirements, see Authoring Configurations.