https://www.sheldonhull.com/fix-terraform-provider-path-in-state/
2021-03-10T21:01:09Z
262 words
2 minutes
Fixing Terraform provider paths in state might be required after upgrading to 0.13-0.14 if your prior state has the following paths.
First, get the terraform providers from state using: terraform providers
The output should look similar to this:
To fix these, try running the commands to fix state.
Please adjust to the required providers your state uses, and make sure your tooling has a backup of the state file in case something goes wrong.
Terraform Cloud should have this backed up automatically if it’s your backend.
1
2
3
4
terraform state replace-provider -- registry.terraform.io/-/aws registry.terraform.io/hashicorp/aws
terraform state replace-provider -- registry.terraform.io/-/random registry.terraform.io/hashicorp/random
terraform state replace-provider -- registry.terraform.io/-/null registry.terraform.io/hashicorp/null
terraform state replace-provider -- registry.terraform.io/-/azuredevops registry.terraform.io/microsoft/azuredevops
The resulting changes can be seen when running terraform providers and seeing the dash is now gone.
If you have multiple workspaces in the same folder, you’ll have to run fix on their seperate state files.
This is an example of a quick adhoc loop with PowerShell to make this a bit quicker, using tfswitch cli tool.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
tfworkspacelist|ForEach-Object{$workspace=$_.Replace('*','').Trim()Write-BuildGreen"Selecting workspace: $workspace"tfworkspaceselect $workspacetfswitch0.13.5tf013.upgradetfswitchtfinit# Only use autoapprove once you are confident of these changesterraformstatereplace-provider-auto-approve--registry.terraform.io/-/awsregistry.terraform.io/hashicorp/awsterraformstatereplace-provider-auto-approve--registry.terraform.io/-/randomregistry.terraform.io/hashicorp/randomterraformstatereplace-provider-auto-approve--registry.terraform.io/-/nullregistry.terraform.io/hashicorp/nullterraformstatereplace-provider-auto-approve--registry.terraform.io/-/azuredevopsregistry.terraform.io/microsoft/azuredevopstfvalidate}
Webmentions
(No webmentions yet.)