如何使用Terraform连接到OCI?

问题描述

我很有趣,并且使用https://github.com/terraform-providers/terraform-provider-ociterraform OCI提供程序连接到OCI的游戏

我失败的连接地形是:

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
}

以及在我的var.tf中引用的相应pem文件

variable "private_key_path" {
  type    = string
  default = "~/.ocI/Oci_api_key.pem"
}

我得到的错误是:

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

我正在按照此步骤设置正确的凭据:https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm

如何解决此问题?

多亏了约翰·汉利(John Hanley),我将var.tf修改为以下代码才有效!请注意从~/.oci到完整路径/Users/jnevill/.oci的更改。这是在Macos上使用Brew安装的terraform

variable "private_key_path" {
  type    = string
  default = "/Users/jnevill/.ocI/Oci_api_key.pem"
}

解决方法

非常感谢您提供一个简单的解决方案-感谢约翰·汉利(John Hanley)向我指出了正确的方向。简而言之,~在private_key_path变量中无效。

解决方案

将pem参考从~更改为/Users/YourUserName/

这使terraform能够正确引用pem文件。

变量失败

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

工作变量

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