Our Terraform project was upgraded to 0.12 sometime ago by a former colleague (no idea how it was tested after upgrading). Now, when I run terraform plan in the project, I get this error:
Error: Failed to instantiate provider “local” to obtain schema: Incompatible API version with plugin. Plugin version: 4, Client versions: [5]
Our project configs include four resource "local_file" sections, but when I comment them out I get the same error. Any suggestions on how I can fix this greatly appreciated!
It sounds like you have an older copy of the local provider already installed in your .terraform directory, and so Terraform is trying to use it in preference to downloading a newer version.
There are a couple different ways you can proceed here:
If you just want a one-off local solution, you could try just deleting the .terraform directory and running terraform init to get Terraform to re-install all of the dependencies. That should either get you into a working state or give you a message explaining why that’s not possible (e.g. if the local provider is constrained to only versions that are not Terraform 0.12-compatible.)
Alternatively, you could add an explicit version constraint to the configuration to indicate that only the versions that are v0.12-compatible are acceptable, and then run terraform init and Terraform should see that your existing installed version is not compatible and upgrade it.
To add the version constraint, either find an existing Terraform block or create a new one and put the required_providers block inside it:
terraform {
required_providers {
local = "~> 1.2.0"
}
}
An advantage of an explicit version constraint is that it should also fix things for anyone else who is in the same situation as you, of having an existing .terraform directory containing plugin versions that are no longer appropriate. If you’d like to do it for the AWS provider too then a suitable version constraint could be "~> 2.7.0", where 2.7.0 is the release that introduced Terraform 0.12 compatibility.