Getting below while trying to run terraform plan through jenkins where my state file is present in remote storage account. I see the tf version in state file is 0.12 and provider version for azurerm is 2.85.
This pipeline was last upgraded to these versions and haven’t been in use since then. How do I fix these errors? I have seen this link as well but I cannot afford to delete my tf state file .
As documented in that link you provided, it sounds like you’ve combined an upgrade of Terraform, with an upgrade of a provider, in a way which isn’t supported.
So, you’re going to have to undo your upgrade, and upgrade one at a time, making sure you’ve had a successful apply run before upgrading the other.
How do I undo my upgrade? Can you please share the steps to do that. and what should I undo tf version or provider version?
No, I can’t. I can’t see your code, so this is something you must figure out, since you know or can find out details about your specific deployment.
I’m not sure, you may need to try both.
The versions you are working with are so old that they predate me ever learning Terraform, so I have no relevant experiences myself.
This error message is discussing a situation that can arise in some rare cases if you upgrade components in an incorrect order. The underlying details here are that Terraform v0.12 introduced a new type system for Terraform which included storing resource data in a different way in the state file. Under Terraform v0.11 the provider schema lived only inside the provider, and so Terraform Core alone cannot upgrade to the new format and instead it asks the provider to perform the upgrade.
Unfortunately it’s been so long now since the Terraform v0.12 release that support for that upgrade path has been phased out by some providers, and so I think what’s happened here is that you are using a newer version of at least one provider that no longer supports this automatic upgrade step.
The main time period for upgrading to Terraform v0.12 was late 2019 and early 2020, so my suggestion would be to refer to the changelog of each provider you are using and choose a version number of that provider whose release date was in January or February of 2020, and specify that as an exact version constraint in you configuration.
terraform init -upgrade to install that different version – despite the name, the “upgrade” option will also downgrade if the version constraints require it – you can hopefully run
terraform apply to apply any changes from your configuration and also, at the same time, upgrade the data in your state to the new format.