Creating a Terraform Configuration File
Learn how to create a terraform configuration file with Terraform domain-specific language or JSON format if the files need to be machine-readable.
Terraform uses declarative syntax to describe your Oracle Cloud Infrastructure (OCI) infrastructure and then persist it in configuration files that can be shared, reviewed, edited, versioned, preserved, and reused. See Configuration Syntax. Terraform configuration files can use either of two formats: Terraform domain-specific language (HashiCorp Configuration Language format [HCL]), which is the recommended approach, or JSON format if the files need to be machine-readable. Configuration files that use the HCL format end with the .tf
file extension; those using JSON format end with the .tf.json
file extension. The Terraform format is human-readable, while the JSON format is machine readable.
Use Terraform configurations to define resources that your solution or application requires at the time of deployment. Resources can create Oracle Cloud 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. Terraform, then, converts your Oracle Cloud Infrastructure configurations into a set of API calls against the Oracle Cloud Infrastructure API endpoints. The key to writing Terraform configuration is understanding how to abstract the desired infrastructure conceptually into Terraform configuration syntax.
Depending on your level of experience in developing Terraform Configurations you can proceed with Getting Started with a Marketplace Stack Template or Authoring your own Terraform Configurations sections.
Getting Started with a Marketplace Stack Template
A collection of examples that allows Oracle Cloud Infrastructure Marketplace publishers to get a quick start deploying Applications in Oracle Cloud Infrastructure is available at OCI Quickstart Template. This repository contains the template that can be used for accelerating the construction of Stacks that runs from local Terraform CLI, OCI Resource Manager and Cloud Shell.
We recommend getting started by creating a clone of the oci-quickstart-template repository:
$> git clone https://github.com/oracle-quickstart/oci-quickstart-template.git $> cd oci-quickstart-template
Terraform configuration (.tf) files have specific requirements, depending on the components that are defined in the file. For example, you might have your Terraform provider defined in one file (provider.tf), your variables defined in another (variables.tf), your data sources defined in yet another. Marketplace Quickstart Stack template groups similar resources into individual files, but note that the file system layout is only a sample reference.
Deploy an Instance with a Custom Image
To create an instance from a custom image, do the following:
-
Locate oci_core_instance resource in compute.tf file and set source_details to local.compute_image_id in the oci-quickstart-template you just cloned. Local variable local.compute_image_id can be set to a custom image ocid or a marketplace image ocid. based on mp_subscription_enable flag.
-
Modify variables.tf set compute_image_id variable default attribute value to the OCID of the custom image that you have created following Task 2 in Using Partner Portal for OCI Stack Listing.
Authoring your own Marketplace Stack
oci-quickstart-template repository serves a starting point for your Terraform configurations, but does not limit you to author your own Infrastrucutre as Code. For reference to more examples, see Oracle Cloud Infrastructure Terraform Provider for OCI : terraform-provider-oci/docs/examples. Ensure that your Terraform files comply with Marketplace Guidelines for Stacks.