Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect to OCI using Terraform?

I'm having fun and games connecting to OCI using the Terraform OCI provider from https://github.com/terraform-providers/terraform-provider-oci

My failing connection terraform is:

provider "oci" {
  tenancy_ocid         = var.tenancy_ocid
  user_ocid            = var.user_ocid
  fingerprint          = var.fingerprint
  private_key_path     = var.private_key_path
  private_key_password = var.private_key_password
  region               = var.region
}

with a corresponding pem file referenced in my var.tf of:

variable "private_key_path" {
  type    = string
  default = "~/.oci/oci_api_key.pem"
}

The error I get is:

Error: can not create client, bad configuration: did not find a proper configuration for private key

I'm following this to setup the right credentials: https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm

How do I fix this issue?

Thanks to John Hanley I modified my var.tf to the following at it worked! Note the change from ~/.oci to a full path of /Users/jnevill/.oci. This was on Macos using brew installed terraform.

variable "private_key_path" {
  type    = string
  default = "/Users/jnevill/.oci/oci_api_key.pem"
}
like image 262
j3r3m7 Avatar asked Jan 31 '26 03:01

j3r3m7


1 Answers

Thankfully a simple solution to this one - thanks to John Hanley pointing me in the right direction. In short the ~ wasn't working in the private_key_path variable.

Solution

Change the pem reference from ~ to /Users/YourUserName/

This enables terraform to reference the pem file correctly.

Failing var

variable "private_key_path" {
  type    = string
  default = "~/.oci/oci_api_key.pem"
}

Working var

variable "private_key_path" {
  type    = string
  default = "/Users/jnevill/.oci/oci_api_key.pem"
}
like image 73
j3r3m7 Avatar answered Feb 03 '26 04:02

j3r3m7