Error: No changes. Your infrastructure matches the configuration

Hi I am trying to bring up a ec2 instance with terraform but I am getting this error:

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.

The resources are not being created it says matches the configuration, can anyone tell?

Hi @suryakolla373
If it’s saying that, then you should have a terraform.tfstate file present
Open this in an editor (it is JSON) and find the aws_instance that must be present in it. Within that record’s attributes will be an AWS instance ID.
Verify whether the instance exists by looking up the instance ID in AWS console.

Also, and this catches people out, be sure that the AWS region the provider has deployed to is the same region you are looking at in the console.

1 Like

terraform.tfstate has this below content and no instance ID init and I checked in the other regions as well. instance is not created

{

“version”: 4,

“terraform_version”: “1.2.7”,

“serial”: 1,

“lineage”: “aa082dc4-bb98-a84e-17cb-3997020bf857”,

“outputs”: {},

“resources”: []

}

Yup, that’s an empty state file which means no resources.
To have this, then you can’t have anything defined in your .tf file.

If you think this is wrong, please paste in your .tf file that declares the AWS instance - replacing anything sensitive with xxx

When pasting code, please place inside ``` (triple backtick) - or press </> button in post editor so it is

formatted
like
this

Hi This is my terraform code but it is not creating instance

provider “aws” {
region = “us-east-1”
access_key = “MOOn45YeaiMad*”
secret_key = “bcbcsdfwwfdafegsvsbhbbldlbdn”
}
resource “aws_instance” “Terraform_instance” {
ami = ami-08c40ec9ead489470
instance_type = “t2.micro”
}

C:\Users\surya\Documents\Terraform_project\Terraform_practice>terraform init

Initializing the backend…

Initializing provider plugins…

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running “terraform plan” to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

C:\Users\surya\Documents\Terraform_project\Terraform_practice>terraform plan

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.

C:\Users\surya\Documents\Terraform_project\Terraform_practice>terraform apply

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.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Hi @suryakolla373

Just checking this is your post in Slack

If so, then your issue is solved.

May i know what is the solution of this issue. Even I have same issue.

Hi Surya.
please share the solution if you have resolved it

can you share how you structure your modules if you have any and if so are they structured using modules like the

├── main.tf
├── variables.tf
├── outputs.tf
├── networking
│ ├── vpc.tf
│ ├── variables.tf
│ └── outputs.tf
├── compute
│ ├── ec2.tf
│ ├── variables.tf
│ └── outputs.tf
└── database
├── sql.tf
├── variables.tf
└── outputs.tf

if so Reference modules in the main configuration: In the main.tf file something like:
module “networking” {
source = “./networking”
}

then try and run your terraform commands let me know if this help

check below and try this out