Failed to marshal state to json

Failed to marshal state to json: schema version 0 for azurerm_template_deployment.container in state does not match version 1 from the provider

hi guys - any pointers on this?

Hi @DevOpsCat,

Can you provide more context? What steps did you take, and what command is returning the given error?

Of course, yes.

So I’m trying to read the state file with a terraform show jq query.

So within an azdo pipeline I’m running a terraform init, grabbing the state file then trying to query the state file.

This was working up until today.

Guessing the state file may have changed schema somehow?

terraform show requires that you have the same providers which encoded the state so it can ensure the schemas match exactly. In this case it seems the azurerm provider has been upgraded to a version which changed the azurerm_template_deployment schema. Make sure your configuration is pinning the required providers to prevent unexpected changes.

Thanks for your help, it really is appreciated. Any tips of getting them back in synch?

You can either specify the provider version in the configuration so that init will fetch the previous version used, or you could run a plan+apply which should refresh the resource and update the state to the newest schema.