Review requirements and recommendations for Terraform configurations used with Resource Manager. Use Terraform and Resource Manager to install, configure, and manage resources using the infrastructure-as-code model.
In addition to writing your own Terraform configuration file, you also have the option to generate a Terraform configuration from either an existing compartment using resource discovery or a sample template.
Caution
Do not provide user credentials or other confidential information in your Terraform configurations.
Requirements
Terraform configuration files used with Resource Manager must
meet the following requirements.
Terraform Provider 🔗
When using Resource Manager, the region
field in the provider "oci" block is the only required field.
For more information about defining providers, see Configuration File Requirements.
File Structure 🔗
Resource Manager requires the following file structure
for the Terraform configuration:
The working directory must contain at least one .tf file. The working directory cannot contain a .terraform directory.
The working directory is the path from which to run Terraform. By default, the working directory is the root directory of your configuration (for an uploaded configuration, the root of your .zip file). When using the API, you can specify a different location for the working directory by setting the workingDirectory parameter.
We recommend using a schema
document with your Terraform configuration to facilitate user entry in the
Oracle Cloud Infrastructure
Console.
Resource Manager does not have requirements for variables in Terraform configurations. Resource Manager supports the native Terraform behavior for handling variables. Terraform sets variables from your variable definitions that use supported type constraints. When you run a job, the stack's variable values are added as environment variables in the Resource Manager Terraform host. For example, the VCN specified in a stack for a given VCN variable is added as an environment variable.
Note
When defined in the Terraform configuration, the following variables automatically prepopulate with values on the Console pages used to create and edit the stack. The stack's values are used when you select the Terraform actions Plan, Apply, and Destroy.
tenancy_ocid (tenancy OCID)
compartment_ocid (compartment OCID)
region (region)
current_user_ocid (OCID of the current user)
Third-party Provider Configuration 🔗
Reference third-party Terraform providers in Terraform configurations used with Resource Manager.
As with any provider configuration, we recommend specifying versions. Dependency lock files are automatically managed for new and updated stacks.
Providers are updated within the version constraints of the Terraform configuration.
For instructions, see Retrieving the Latest Providers.
For more information about adding providers to Terraform configurations, see Provider Configuration.
Example Terraform Configuration for Resource Manager 🔗
The following example shows a Terraform configuration that's contained in a single file. This basic sample defines only one Terraform provider, one Oracle Cloud Infrastructure resource, and a set of variables.
More often, Terraform configurations consist of two or more files bundled together (for an uploaded configuration, the files would be bundled in a .zip file). To see more complex Terraform configurations that include multiple files, explore the examples at Terraform Oracle Cloud Infrastructure Provider Examples.
Tip
Quickly create stacks with example OCI Terraform configurations. Go to Terraform Oracle Cloud Infrastructure Provider Examples, navigate to the folder for the configuration you want (such as adm), and then select the Deploy to Oracle Cloud button under "Magic Button" in the readme.