jigar shah
jigar shah

Reputation: 11

Issue with Terraform apply [using CodePipeline]

We recently migrated to Terraform v1.1.9 from [0.11.11]. We adjusted our TF init and Plan accordingly in our Source code. Code runs fine till the stage of TF plan. "Current.tfplan" also gets created. On the stage of "Terraform apply" getting below error with "Error: Inconsistent dependency lock file".

AWS provider version being used is:

*terraform {
  required_providers {
  aws = {
  source  = "hashicorp/aws"  
  version = "~> 4.7.0"
  }
}*

Error message

**╷
│ Error: Inconsistent dependency lock file
│ 
│ The following dependency selections recorded in the lock file are
│ inconsistent with the configuration in the saved plan:
│   - provider registry.terraform.io/hashicorp/aws: required by this configuration but no version is selected
│ 
│ A saved plan can be applied only to the same configuration it was created
│ from. Create a new plan from the updated configuration.
╵
╷
│ Error: Inconsistent dependency lock file
│ 
│ The given plan file was created with a different set of external dependency
│ selections than the current configuration. A saved plan can be applied only
│ to the same configuration it was created from.
│ 
│ Create a new plan from the updated configuration.**

Any help would be really appreciated!

Regards,

Upvotes: 1

Views: 1422

Answers (1)

Tapan Hegde
Tapan Hegde

Reputation: 1328

@jigar shah I would suggest you run below command, which may fix your issue.

terraform init -upgrade

I tried to recreate your problem and was able to run terraform apply command without any issue. I was using terraform 1.0.12 version and recently upgraded to terraform 1.1.9.

Just sharing my main.tf contents, please check if it helps your use case

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.7.0"
    }
  }
}

provider "aws" {
  profile = "default"
  region  = "us-west-2"
}

resource "aws_instance" "app_server" {
  ami           = "ami-830c94e3"
  instance_type = "t2.micro"

  tags = {
    Name = "ExampleAppServerInstance"
  }
}

My AWS provide block looks likes this

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.7.0"
    }
  }
}

Upvotes: 1

Related Questions