Skip to content

OCI Backend cannot configure "bucket" attribute using environmental variable #37277

Open
@maksym-dilanian

Description

@maksym-dilanian

Terraform Version

Terraform v1.12.2
 on linux_amd64

Terraform Configuration Files

provider "oci" {
  auth                = "SecurityToken"
  config_file_profile = "DEFAULT"
  region              = "us-chicago-1"
}

terraform {
  required_version = ">= 1.12.0"
  required_providers {
    oci = {
      source  = "oracle/oci"
      version = "~> 6.0"
    }
  }
  backend "oci" {
    namespace         = "REDACTED"
    auth              = "SecurityToken"
    config_file_profile = "DEFAULT"
  }
}

resource "oci_objectstorage_bucket" "this" {
  compartment_id = "ocid1.compartment.oc1..REDACTED"
  name           = "my-bucket"
  namespace      = "REDACTED"
}

Debug Output

terraform_trace.log

Expected Behavior

OCI backend configuration argument bucket is set using environmental variable OCI_bucket as described in the documentation:

You can configure the OCI Terraform backend using environment variables. This provides flexibility and simplifies automation workflows.
For any backend attribute (e.g., region), you can set its value using one of the following environment variable formats:
[...]
OCI_ – OCI SDK-compatible environment variable

Actual Behavior

init fails:

+ terraform init -force-copy
 Initializing the backend...
 bucket
   The name of the OCI Object Storage bucket.
 
   Enter a value: 
 !!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 Terraform crashed! This is always indicative of a bug within Terraform.
 Please report the crash with Terraform[1] so that we can fix this.
 
 When reporting bugs, please include your terraform version, the stack trace
 shown below, and any additional information which may help replicate the issue.
 
 [1]: https://github.com/hashicorp/terraform/issues
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 panic: invalid path: at step 0: cannot access attributes on a null value
 goroutine 1 [running]:
 runtime/debug.Stack()
 	runtime/debug/stack.go:26 +0x5e
 github.com/hashicorp/terraform/internal/logging.PanicHandler()
 	github.com/hashicorp/terraform/internal/logging/panic.go:84 +0x16a
 panic({0x31be1a0?, 0xc0005e13b0?})
 	runtime/panic.go:792 +0x132
 github.com/hashicorp/terraform/internal/backend/backendbase.GetPathDefault({{{0x4067f80?, 0xc0005e1290?}}, {0x0?, 0x0?}}, {0xc0005e1350?, 0x472e19?, 0x10?}, {{{0x4067d18, 0xc00012eccf}}, {0x31be1a0, ...}})
 	github.com/hashicorp/terraform/internal/backend/backendbase/helper.go:28 +0x128
 github.com/hashicorp/terraform/internal/backend/backendbase.GetAttrDefault({{{0x4067f80?, 0xc0005e1290?}}, {0x0?, 0x0?}}, {0x3932a0d, 0x6}, {{{0x4067d18, 0xc00012eccf}}, {0x31be1a0, 0xc0005e1340}})
 	github.com/hashicorp/terraform/internal/backend/backendbase/helper.go:39 +0x137
 github.com/hashicorp/terraform/internal/backend/remote-state/oci.getBackendAttrWithDefault({{{0x4067f80?, 0xc0005e1290?}}, {0x0?, 0x0?}}, {0x3932a0d, 0x6}, {0x0?, 0x0?})
 	github.com/hashicorp/terraform/internal/backend/remote-state/oci@v0.0.0-00010101000000-000000000000/util.go:81 +0xf2
 github.com/hashicorp/terraform/internal/backend/remote-state/oci.getBackendAttr(...)
 	github.com/hashicorp/terraform/internal/backend/remote-state/oci@v0.0.0-00010101000000-000000000000/util.go:86
 github.com/hashicorp/terraform/internal/backend/remote-state/oci.(*Backend).Configure(0xc0006e57a0, {{{0x4067f80?, 0xc0005e1290?}}, {0x0?, 0x0?}})
 	github.com/hashicorp/terraform/internal/backend/remote-state/oci@v0.0.0-00010101000000-000000000000/backend.go:221 +0x89
 github.com/hashicorp/terraform/internal/command.(*Meta).backendInitFromConfig(0xc0000ece00, 0xc000922e60)
 	github.com/hashicorp/terraform/internal/command/meta_backend.go:1421 +0x7a4
 github.com/hashicorp/terraform/internal/command.(*Meta).backend_C_r_s(0xc0000ece00, 0xc000922e60, 0x6665a983, 0xc000c00d20, 0xc000817538)
 	github.com/hashicorp/terraform/internal/command/meta_backend.go:989 +0x976
 github.com/hashicorp/terraform/internal/command.(*Meta).backendFromConfig(0xc0000ece00, 0xc000817538)
 	github.com/hashicorp/terraform/internal/command/meta_backend.go:638 +0x1865
 github.com/hashicorp/terraform/internal/command.(*Meta).Backend(0xc0000ece00, 0x0?)
 	github.com/hashicorp/terraform/internal/command/meta_backend.go:105 +0x6a
 github.com/hashicorp/terraform/internal/command.(*InitCommand).initBackend(0xc0000ece00, {0x4067ab0?, 0xc0006f80f0?}, 0xc0009e8000, {{0x394b5fb?, 0xc000817680?}, 0xc0007e6fc0?}, 0x48, {0x406de20, 0xc000122370})
 	github.com/hashicorp/terraform/internal/command/init.go:499 +0x72f
 github.com/hashicorp/terraform/internal/command.(*InitCommand).Run(0xc0000ece00, {0xc000120230?, 0x0?, 0x0?})
 	github.com/hashicorp/terraform/internal/command/init.go:187 +0xf6e
 github.com/hashicorp/cli.(*CLI).Run(0xc000b8c3c0)
 	github.com/hashicorp/cli@v1.1.7/cli.go:265 +0x4de
 main.realMain()
 	github.com/hashicorp/terraform/main.go:339 +0x1deb
 main.main()
 	github.com/hashicorp/terraform/main.go:64 +0x13

Steps to Reproduce

  1. Set environmental variable for bucket
export OCI_bucket="core-01-system"
  1. terraform init -force-copy

Additional Context

Terraform is running in a K8s pod with Jenkins pipeline.

References

Generative AI / LLM assisted development?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions