CodexBloom - Programming Q&A Platform

Terraform Plan Shows Changes for Unmodified Resources After State Refresh

👀 Views: 481 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-12
terraform aws ec2 state bug HCL

After trying multiple solutions online, I still can't figure this out. I'm sure I'm missing something obvious here, but I'm testing a new approach and I'm working with a frustrating scenario with Terraform 1.4.0 where after running `terraform apply`, the `terraform plan` command indicates that certain resources are going to be destroyed and recreated, even though I haven't modified their configurations. For example, I'm using an AWS EC2 instance with the following configuration: ```hcl resource "aws_instance" "example" { ami = "ami-12345678" instance_type = "t2.micro" tags = { Name = "ExampleInstance" } } ``` After applying the configuration, I performed a state refresh using `terraform refresh`, and when I run `terraform plan`, it shows: ``` ~ aws_instance.example id: "i-0abcd1234efgh5678" => "i-0abcd1234efgh5678" ami: "ami-12345678" => "ami-87654321" ``` Notice that it wants to change the AMI, which hasn't changed in my configuration. I've double-checked the actual AMI ID in the AWS console, and it matches the one in my configuration file. I've even run `terraform state pull` to examine the state file directly, and it shows the correct AMI ID. Is there something I'm missing regarding how Terraform handles state, or could this be a bug? I've tried running `terraform init` again and even reinitializing the backend with `terraform init -reconfigure`, but the scenario continues. Any insights or workaround suggestions would be appreciated! Any examples would be super helpful. Any examples would be super helpful. Could this be a known issue?