Terraform error when executing terraform init command
Terraform Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/oci: no available releases match the given constraints >= 4.41.0, ~> 4.59.0
Background:
I got a working terraform project from a friend, when I tried to run in my environment, I am getting this error.
My development environment is oracle developer instance, which is already packed with terraform.
After copying the terraform project, I am trying to do a terraform init
[root@shivin-dev-sg terraform]# terraform init
Initializing modules...
Downloading registry.terraform.io/oracle-terraform-modules/vcn/oci 3.2.0 for vcn...
- vcn in .terraform/modules/vcn
- vcn.drg_from_vcn_module in .terraform/modules/vcn/modules/drg
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/kubernetes versions matching "~> 2.4.1"...
- Finding latest version of hashicorp/local...
- Finding hashicorp/oci versions matching ">= 4.41.0, ~> 4.59.0"...
- Installing hashicorp/kubernetes v2.4.1...
- Installed hashicorp/kubernetes v2.4.1 (signed by HashiCorp)
- Installing hashicorp/local v2.1.0...
- Installed hashicorp/local v2.1.0 (signed by HashiCorp)
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/oci: no available releases match the given constraints >= 4.41.0, ~> 4.59.0
╵
[root@shivin-dev-sg terraform]#
What is the issue and how to fix it?
As you can see from the initalizing provider plugins part, the oci plugin version is 4.41.0 but in our provider.tf the version is 4.59.0. This means somewhere in my machine there is a plugin cache. I need to find delete it for fixing this issue.
Steps to solve the issue:
cd /usr/share/terraform/
rm -rf plugins
cd /root
rm -rf .terraform
cd /path-to-your-terraform
rm -rf .terraform.d
Now, do a terraform init, it will works!!