CodexBloom - Programming Q&A Platform

OCI Resource Manager: Terraform State File implementation guide After Apply

👀 Views: 0 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-09
terraform oci resource-manager HCL

I'm working on a personal project and I've been struggling with this for a few days now and could really use some help. I'm currently using Oracle Cloud Infrastructure (OCI) Resource Manager to manage my infrastructure as code with Terraform. After running `terraform apply`, I noticed that my state file isn't updating as expected. For instance, I added a new compute instance in my configuration: ```hcl resource "oci_core_instance" "example_instance" { availability_domain = "Uocm:PHX-AD-1" compartment_id = var.compartment_id display_name = "example-instance" shape = "VM.Standard2.1" source_details { source_type = "image" image_id = var.image_id } } ``` After executing `terraform apply`, I received the following message: `behavior: behavior refreshing state: 1 behavior(s) occurred: * oci_core_instance.example_instance: behavior getting instance: unauthorized`. I have checked the IAM policies and confirmed that the user has the necessary permissions for managing instances in that compartment. I also verified that the correct credentials are being used. To troubleshoot, I tried refreshing the state with `terraform refresh`, but that didn't help. I even tried running `terraform init` again to ensure that the provider was configured correctly, but I still encounter the same behavior during `apply`. My current Terraform version is 1.0.11, and I am using the OCI provider version 3.0.0. Has anyone experienced similar issues or can share insights on what might be causing the state file not to update? Any suggestions would be greatly appreciated! Is there a better approach? This is part of a larger service I'm building.