Skip to content

Instantly share code, notes, and snippets.

@nodomain
Last active September 10, 2020 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nodomain/e190f358181b16e99de8d63fae25510e to your computer and use it in GitHub Desktop.
Save nodomain/e190f358181b16e99de8d63fae25510e to your computer and use it in GitHub Desktop.
Terraform 0.13: Replace "namespaceless" providers in state with the HashiCorp namespace variant
terraform state pull | grep provider | grep registry.terraform.io/- | uniq | cut -d"\\" -f2 | cut -d"\"" -f2 | sort | uniq \
| while IFS= read -r line; do terraform state replace-provider -auto-approve ${line} ${line/-/hashicorp} ; done
@nodomain
Copy link
Author

nodomain commented Sep 9, 2020

This one-liner fixes the providers for Terraform 0.13 in your existing state file.
More background: https://www.terraform.io/upgrade-guides/0-13.html

@nodomain
Copy link
Author

If it is used in a Makefile then make sure to use $$ instead of $ to correctly expand the 'line' variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment