Terraform Google Provider 8.0 Migration Guide
In this article
This guide walks you through migrating your Terraform configurations to the Google provider version 8.0 safely. It covers preparation, step-by-step changes, common pitfalls, and troubleshooting so you can upgrade with minimal disruption to your infrastructure.
What You'll Need
- Access to your Terraform state files (local or remote backend).
- Terraform CLI installed (version 1.3 or later recommended).
- Your existing Google provider configuration files.
- A test environment or a way to run `terraform plan` without applying changes.
- Familiarity with the `terraform state` commands for potential state surgery.
Step-by-Step
- Read the upgrade guide. Start by reading the official Google Provider 8.0 Upgrade Guide in the Terraform Registry. It lists all breaking changes, including removed resources, changed attribute names, and new required fields. Bookmark it and keep it open.
- Check your current version. Run
terraform versionand note your provider version. Also check your configuration files for any version constraints (e.g., inrequired_providers). - Back up your state. Before any upgrade, back up your state file. If using remote state, download a copy or enable versioning on the bucket. This is your safety net.
- Update the provider version. In your Terraform configuration, change the
versionconstraint for the Google provider to~> 8.0(or>= 8.0, < 9.0). For example:terraform { required_providers { google = { source = "hashicorp/google" version = "~> 8.0" } } } - Run
terraform init. This downloads the new provider version. If you have a lock file (.terraform.lock.hcl), it will update it. Check the output for any warnings about removed or deprecated features. - Run
terraform plan. This is the critical step. The plan will show you exactly what changes Terraform intends to make. Look for:- Resources being replaced (due to name changes or required fields).
- Attributes being removed or renamed.
- New required arguments that you need to add.
- Fix configuration errors. The plan will likely show errors for resources that no longer exist or have changed. Use the upgrade guide to update your configuration. Common fixes include:
- Renaming resource types (e.g.,
google_compute_instancemight change in some edge cases). - Changing attribute names (e.g.,
zonetozoneis unchanged, but some fields likeboot_diskmay have nested changes). - Adding new required fields (e.g.,
projectmight become required in some data sources).
- Renaming resource types (e.g.,
- Use
terraform state mvif necessary. If a resource type was renamed, you can move the state to the new address. For example:
Only do this if the resource is functionally the same.terraform state mv 'google_compute_instance.foo' 'google_compute_instance_v1.foo' - Run
terraform planagain. Repeat the plan until it shows no errors and only the changes you expect (ideally, no changes at all if your configuration is already correct). - Apply in a test environment first. If possible, apply the changes in a non-production environment to verify everything works. If you cannot, proceed with caution.
- Apply the changes. Once the plan is clean, run
terraform apply. Review the plan one last time before confirming. - Verify your infrastructure. After applying, check that your resources are functioning as expected. Look at the Terraform output and, if needed, use the Google Cloud Console.
Common Mistakes
- Skipping the upgrade guide. The guide is there for a reason. Missing a breaking change can cause unexpected resource replacement.
- Not backing up state. If something goes wrong, you may need to restore. A backup is essential.
- Ignoring plan warnings. Warnings about deprecated features may become errors in the next major version. Address them now.
- Using
terraform state mvblindly. Only move state if the resource is truly equivalent. Otherwise, you risk losing track of your infrastructure. - Forgetting to update module providers. If you use modules, ensure their
required_providersblocks are also updated.
Tips
- Work in small batches. Migrate one resource type at a time if your configuration is large.
- Use
terraform plan -out=tfplanto save the plan and review it carefully. - Leverage
terraform fmtto keep your code clean after edits. - Consider using a version control system (like Git) to track changes to your Terraform files.
- If you use a CI/CD pipeline, test the upgrade in a separate branch first.
Troubleshooting
If the plan shows errors, here are common issues and how to resolve them:
- Error: "Resource type not found" – The resource type was removed or renamed. Check the upgrade guide for the new name and update your configuration.
- Error: "Attribute not found" – An attribute was renamed or removed. Use the upgrade guide to find the replacement, or remove the attribute if it's no longer needed.
- Error: "Missing required argument" – A new required field was added. Add the field with an appropriate value.
- Plan shows unexpected resource replacement – This often happens when a resource's
nameoridchanges. Check if you need to useterraform state mvor if the replacement is unavoidable. - Provider initialization fails – Ensure your network can reach the Terraform registry. If you use a mirror, update it.
- State lock errors – If you're working in a team, ensure no one else is applying changes. Use
terraform force-unlockonly if you're sure the lock is stale.
Frequently Asked Questions
Do I need to change my Terraform code if I use modules?
Yes, you may need to update the module's required_providers block and any resource definitions inside the module. Check the module's documentation for compatibility.
Can I skip versions and go from 5.x to 8.0 directly?
It's possible, but not recommended. Each major version has its own breaking changes. It's safer to upgrade incrementally (5→6→7→8) to catch issues early.
What if I don't want to upgrade?
You can stay on your current version, but you'll miss out on new features and security fixes. Eventually, the provider may stop being supported.
Will my state file be compatible?
Yes, Terraform state is generally forward-compatible. However, if a resource is renamed, you'll need to use terraform state mv to update the state.
How do I know if a resource was renamed?
The upgrade guide lists all renames. You can also run terraform plan and look for resources that show as "must be replaced" – that's a clue.
What if I use a custom provider binary?
You'll need to download the new binary for version 8.0 and update your configuration to point to it.