You can store Terraform state files in the
Oracle Cloud Infrastructure Object Storage. Doing so requires that you configure a backend using one of the Terraform backend types.

Terraform supports various backend types to allow flexibility in how state files are loaded into Terraform. (For more
information, see Terraform Backend Types.) For our purposes, we address two of these approaches:

Using the HTTP backend type allows you to store state using a simple REST client. With the HTTP backend type, you can
easily fetch, update, and purge state using the HTTP GET, POST, and DELETE methods.

To configure the HTTP backend to store your Oracle Cloud Infrastructure Terraform state files, do the following:

Creating a pre-authenticated request in Oracle Object Storage enables accessing a bucket or object in the Oracle Cloud
Infrastructure without needing to provide credentials. To do so, you must create a pre-authenticated request that has
read/write permissions to the object store where you intend to save the Terraform state file. You can do so in any of
three ways: by using the Console UI, by using the command line interface (CLI), or by using the REST APIs.

Note
A state file must exist in the bucket before you create the pre-authenticated request. This file can be an existing state file, or an empty file for the initial state.

Configuring the S3-compatible backend requires that the account be enabled with S3 authentication keys, which are set on a per-user basis.

In the Console, open the navigation menu, then, under Governance and Administration, navigate to Identity, then Users.
Under User Details, click Amazon S3 Compatibility API Keys. For more guidance,
see Working with Amazon S3 Compatibility API Keys.

Set the location for the credentials file. The default location is ~/.aws/credentials. You can set an alternate location by using the S3 backend shared_credentials_file option.

Warning
Never set the access_key and the secret_key attributes in the same Terraform backend configuration, since this creates a security risk.

Configure the [default] entry in the credentials file with the appropriate object storage credentials.
The file can contain any number of credential profiles. If you provide a different profile name, you must also
update the backend profile option in your Terraform configuration file.

The S3 backend configuration can also be used for the terraform_remote_state data source to enable sharing state across Terraform projects.

Once you have configured the backend, you must run terraform init to finish the setup.
If you already have an existing terraform.tfstate file, then Terraform prompts you to confirm that the current state file is the one to upload to the remote state.