Terraform state replace-provider update state with wrong data

We upgraded terraform version and we have a problem with terraform remote state. Basiacaly I run this command to update azurerm provider:

terraform state replace-provider ' '

Right now when I run plan command it shows me some errors. All are the same but resource if different. For example:

To work with module.name.module.lb_name.azurerm_lb_probe.instance
its original provider configuration at
provider[""] is required, but it has been
removed. This occurs when a provider configuration is removed while objects
created by that provider still exist in the state. Re-add the provider
configuration to destroy
module.name.module.lb_name.azurerm_lb_probe.instance, after which
you can remove the provider configuration again.

Basically the state was updated and the provider looks like this:

"provider": "provider.azurerm"

but it should look like this:

"provider": "provider[\""]"

Is there any way to update it via terraform commands or the only way to fix it is to edit state file manually?

5

1 Answer

When you replace the providers for the Terraform upgrade with the command:

terraform state replace-provider ' '

OK, there is no problem. And then you can use the command below to check the current providers:

terraform providers

The screenshot will show like this:

enter image description here

At this time, the providers are the same as the requirement. Then you need to init again to pull the current providers to replace the existing ones with the command below:

terraform init

enter image description here

This is the step you have missed.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like