OCI Backend
The OCI backend stores state in Oracle Cloud Infrastructure (OCI) Object Storage with support for encryption and state locking.Implementation
Location:/internal/backend/remote-state/oci/backend.go
Use Cases
- Managing Oracle Cloud Infrastructure resources
- Teams using OCI services
- Oracle-based cloud environments
- Multi-cloud with OCI component
Basic Configuration
Required Configuration
bucket
- Type: String
- Required: Yes
- Description: The name of the OCI Object Storage bucket
namespace
- Type: String
- Required: Yes
- Description: The namespace of the OCI Object Storage
Optional Configuration
key
- Type: String
- Optional: Yes
- Default:
"terraform.tfstate" - Description: The name of the state file stored in the bucket
workspace_key_prefix
- Type: String
- Optional: Yes
- Default:
"env" - Description: The prefix applied to the non-default workspace state path
region
- Type: String
- Optional: Yes
- Description: OCI region where the bucket is located
us-phoenix-1- Phoenix, AZus-ashburn-1- Ashburn, VAeu-frankfurt-1- Frankfurt, Germanyuk-london-1- London, UKap-tokyo-1- Tokyo, Japan
Authentication Methods
The OCI backend supports multiple authentication methods:1. API Key Authentication
private_key or private_key_path, not both.
With password-protected key:
2. Config File Profile
~/.oci/config
Config file format:
3. Instance Principal
4. Resource Principal
5. Security Token
config_file_profile to be set.
Encryption
KMS Encryption
- Type: String
- Optional: Yes
- Description: OCID of a KMS master encryption key for encrypting the state file
Customer-Supplied Encryption
- sse_customer_key - Base64-encoded 256-bit encryption key
- sse_customer_key_sha256 - Base64-encoded SHA256 hash of the key
- sse_customer_algorithm - Encryption algorithm (must be βAES256β)
kms_key_id and sse_customer_key simultaneously.
State Locking
The OCI backend uses object lock files for state locking:- Lock file:
<state-path>.tflock - Automatic locking during state-modifying operations
- Lock release on operation completion or error
Configuration Options Summary
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
bucket | string | Yes | - | Object Storage bucket name |
namespace | string | Yes | - | Object Storage namespace |
key | string | No | terraform.tfstate | State file name |
workspace_key_prefix | string | No | env | Workspace path prefix |
region | string | No | - | OCI region |
tenancy_ocid | string | No | - | Tenancy OCID |
user_ocid | string | No | - | User OCID |
fingerprint | string | No | - | API key fingerprint |
private_key | string | No | - | Private key content |
private_key_path | string | No | - | Path to private key |
private_key_password | string | No | - | Private key password |
auth | string | No | ApiKey | Authentication method |
config_file_profile | string | No | - | Config file profile name |
kms_key_id | string | No | - | KMS key OCID |
sse_customer_key | string | No | - | Customer encryption key |
sse_customer_key_sha256 | string | No | - | Key SHA256 hash |
sse_customer_algorithm | string | No | - | Encryption algorithm |
Authentication Methods
Valid values for theauth attribute:
ApiKey(default)InstancePrincipalResourcePrincipalSecurityTokenInstancePrincipalWithCertsOKEWorkloadIdentity
Example: Production with KMS Encryption
Example: Using Instance Principal
Example: Multiple Workspaces
IAM Policy Requirements
Minimum permissions for the Object Storage bucket:Best Practices
- Use KMS encryption for production state files
- Use Instance/Resource Principal when running on OCI compute
- Separate buckets for different environments
- Enable versioning on the bucket for state history
- Use dynamic groups for automated workflows
- Restrict bucket access with IAM policies
- Regular backups of state files
- Monitor bucket access logs
- Use compartments to organize resources
- Descriptive workspace names for clarity
Troubleshooting
Finding Your Namespace
In the OCI Console:- Navigate to Object Storage
- Click on Buckets
- Your namespace is displayed at the top