oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
759 stars 675 forks source link

provider version >= 5.44.0 does not read ~/.oci/config #2141

Open xkoomy opened 3 months ago

xkoomy commented 3 months ago

Community Note

Terraform Version and Provider Version

$ terraform -v
Terraform v1.5.7
on linux_amd64
+ provider registry.terraform.io/oracle/oci v5.46.0

Affected Resource(s)

affected_resources = terraform

Terraform Configuration Files

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

terraform {
  required_providers {
    oci = {
      source = "oracle/oci"
      version = "5.46.0" # version >= 5.44.0 does not read ~/.oci/config properly
    }
  }
}

variable "fingerprint" {
  type = string
  default = ""
}

variable "private_key_path" {
  type = string
  default = ""
}

variable "region" {
  type = string
  default = "eu-frankfurt-1"
}

variable "tenancy_ocid" {
  type = string
  default = ""
}

variable "user_ocid" {
  type = string
  default = ""
}

locals {
    compartment_id = "ocid1.compartment.oc1..XXXXXXXXXXX"
    vcn_id = "ocid1.vcn.oc1.eu-frankfurt-1.YYYYYYYY"
}
resource "oci_core_subnet" "test_subnet1" {
    #Required
    cidr_block = "192.168.1.0/24"
    compartment_id = local.compartment_id
    vcn_id = local.vcn_id
    #Optional
    display_name = "testsubnet1"
    dns_label = "testsubnet1"
}

Debug Output

https://gist.github.com/xkoomy/03ede09cb90beafdad426319fa285cff

Panic Output

Expected Behavior

In version 5.43.0 and lower the provider reads the config from ~/.oci/config properly:

$ terraform -v
Terraform v1.5.7
on linux_amd64
+ provider registry.terraform.io/oracle/oci v5.43.0

Your version of Terraform is out of date! The latest version
is 1.8.5. You can update by downloading from https://www.terraform.io/downloads.html

$ terraform plan -input=false
oci_core_subnet.test_subnet1: Refreshing state... [id=ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaaox2hnp7cdh22ujrgkxphk3yp4qrusixsdkvzsj3shis4tz5xqn6q]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Actual Behavior

provider version >= 5.44.0 does not read config from DEFAULT profile in ~/.oci/config

$ TF_LOG=DEBUG OCI_GO_SDK_DEBUG=v TF_LOG_PATH=tf_debug.log terraform plan -input=false
oci_core_subnet.test_subnet1: Refreshing state... [id=ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaaox2hnp7cdh22ujrgkxphk3yp4qrusixsdkvzsj3shis4tz5xqn6q]

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: 401-NotAuthenticated, The required information to complete authentication was not provided or was incorrect.
│ Suggestion: Please retry or contact support for help with service: Core Subnet
│ Documentation: https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_subnet
│ API Reference: https://docs.oracle.com/iaas/api/#/en/iaas/20160918/Subnet/GetSubnet
│ Request Target: GET https://iaas.eu-frankfurt-1.oraclecloud.com/20160918/subnets/ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaaox2hnp7cdh22ujrgkxphk3yp4qrusixsdkvzsj3shis4tz5xqn6q
│ Provider version: 5.46.0, released on 2024-06-12.
│ Service: Core Subnet
│ Operation Name: GetSubnet
│ OPC request ID: 5583dd94ae311060cae6c9fcadcff405/B608A5CDC9DDBBF1C775E2C9D5C3A9AB/DBE4A21DD859A1CBA8BADB18EBD66E45
│
│
│   with oci_core_subnet.test_subnet1,
│   on main.tf line 47, in resource "oci_core_subnet" "test_subnet1":
│   47: resource "oci_core_subnet" "test_subnet1" {
│
╵

Steps to Reproduce

  1. set user, fingerprint, tenancy, key_file as DEFAULT profile in ~/.oci/config
  2. do not provide these values in tfvars, they should be read from the DEFAULT profile
  3. terraform plan -input=false

Important Factoids

no, this is a general error for provider version >= 5.44.0 in lower version (the last one working fine is 5.43.0) provider reads credentials from DEFAULT profile

References

tf-oci-pub commented 3 months ago

Thank you for reporting the issue. We observed the affected resources are not provided in the description or it's incorrect. We request you to add it in issue description as mentioned in below format. Example: affected_resources = oci_core_instance , oci_core_instances

If it's not related to any particular resource then mention affected resource as terraform. Example: affected_resources = terraform

As this works through automation, request you to follow exact syntax.

xkoomy commented 3 months ago

Affected Resource(s) affected_resources = terraform