CodexBloom - Programming Q&A Platform

OCI Resource Manager Stack Failure When Using Compartment ID in Variables

👀 Views: 41 💬 Answers: 1 📅 Created: 2025-06-07
oci terraform resource-manager HCL

I'm having a hard time understanding I'm performance testing and I'm working with an scenario with my OCI Resource Manager stack while trying to use compartment IDs in my Terraform configuration... I'm defining a variable for the compartment ID in my Terraform script, but when I try to apply the stack, I'm getting the following behavior: ``` behavior: Invalid compartment ID on main.tf line 10, in resource "oci_core_instance" "example": 10: compartment_id = var.compartment_id An invalid value was detected for the compartment ID. Please verify and try again. ``` Despite ensuring that the compartment ID is correct and exists in the same region as my resources, this behavior continues. Here's the relevant part of my `main.tf` file: ```hcl variable "compartment_id" { description = "The OCID of the compartment where resources will be created." type = string } resource "oci_core_instance" "example" { availability_domain = "${data.oci_identity_availability_domains.ad.names[0]}" compartment_id = var.compartment_id display_name = "ExampleInstance" shape = "VM.Standard2.1" source_details = { source_type = "image" source_id = "ocid1.image.oc1..example" } } ``` I've verified that my Terraform provider version is `2.0.0` and I've also checked that the compartment ID is valid using the OCI CLI with `oci iam compartment get --compartment-id <YOUR_COMPARTMENT_ID>`. Additionally, I am running the latest version of Terraform, which is `1.3.7`. I’ve tried hardcoding the compartment ID directly into the resource block, and it still results in the same behavior. Is there something I'm missing here? Could it be related to permissions or configurations not set up correctly in the OCI console? Any guidance would be greatly appreciated. I'm working on a REST API that needs to handle this. Is there a better approach? The project is a mobile app built with Hcl. Am I approaching this the right way?