Scenario:

You want to upgrade terraform from v0.13 to v1.0.0. Made changes to versions.tf. Also, you use different workspaces for storing state files.

terraform {
  required_version = ">= 0.13"
  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
  }
}

When the pipeline is run, it validates and inits fine but fails with an error during plan-

Error: Could not load plugin
│
│
│ Plugin reinitialization required. Please run "terraform init".
│
│ Plugins are external binaries that Terraform uses to access and manipulate
│ resources. The configuration provided requires plugins which can't be
│ located,
│ don't satisfy the version constraints, or are otherwise incompatible.
│
│ Terraform automatically discovers provider requirements from your
│ configuration, including providers used in child modules. To see the
│ requirements and constraints, run "terraform providers".
│
│ failed to instantiate provider "registry.terraform.io/-/aws" to obtain
│ schema: unknown provider "registry.terraform.io/-/aws"

 

Solution:

–> Ensure you have the required terraform version installed. Say, want to upgrade to v1.0.0 then it should be installed

–> Change directory to terraform folder where all tf files are available.

–> terraform init

–> terraform workspace select <REPLACE WORKSPACENAME>

–> terraform workspace show   [This is to confirm that you are in the right workspace]

–> Run this command

terraform state replace-provider “registry.terraform.io/-/aws” “registry.terraform.io/hashicorp/aws”

It will show a screen like below and will make changes only if enter yes.

It will prompt to say YES to update. Review the changes and update.