Search code examples
terraformterraform-provider-gcpterraform0.12+infrastructure-as-codeterragrunt

"Invalid legacy provider address" using terragrunt


I am hoping someone can help me with an issue I am having with Terraform/Terragrunt. The versions of each that I am currently using are:

  • Terragrunt v0.35.9
  • Terraform v1.0.11

I am using Terragrunt to deploy project related infrastructure to GCP. I have two seperate Terragrunt projects to split out variables between a test and a production instance of the same GCP solution.

When I run the commands terragrunt init or terragrunt plan -out tf.plan using the test .hcl file, the process completes as expected. However when I run either of these commands using the production .hcl file, I get the following error:

│ Error: Invalid legacy provider address
│ 
│ This configuration or its associated state refers to the unqualified
│ provider "google".
│ 
│ You must complete the Terraform 0.13 upgrade process before upgrading to
│ later versions.

I have looked to see what others have suggested regarding this error, and I have found the following articles:

However the solutions in them are for when the version of Terraform is before the current version, not after, as I am on v1.0.11. Additionally they suggest replacing a provider using the replace-provider command. However it appears that the GCP provider is already up to date in my terraform project, as when I run the terraform providers command I get:

Providers required by configuration:
.
└── provider[registry.terraform.io/hashicorp/google] ~> 4.1.0

Which appears to be the correctly formatted provider for GCP, for versions of Terraform after v0.13.x.

I have also tried deleting the .terragrunt-cache folder and associated lock file for the production instance and attempted to re-run the terragrunt init command, but I keep getting the same error. I find this confusing, as this is working for the test .hcl file, which uses the same underlying Terraform .tf files.

I have noticed that in the test instance a providers folder is being created under the .terragrunt-cache folder, however due to this error this is not being created in the production instance, as can be seen below:

Terraform/Terragrunt folder structure

This screenshot also shows another difference I have noticed between the two Terragrant projects, the production instance is generating a .terragrunt-init-required file, whereas this is not present in the test instance. From what I can see this is related to the fact that the production instance requires initialisation.

These are the contents of my Terraform main.tf file:

terraform {
  backend "gcs" {}
}

provider "google" {
  project = var.deployment_project_id
}

And these are the contents of my Terraform provider.tf file (which I added as part of a suggestion I have seen online, but was not required by the test Terragrunt project to initialise correctly):

terraform {
  required_version = "~> 1.0.11"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 4.1.0"
    }
  }
}

These files are both used by my Terragrunt .hcl files. I would be grateful for any help or ideas on how to resolve this issue.


Solution

  • You seem to have a latest state snapshot that was created with Terraform v0.12 or earlier. That would mean that it would be storing provider configuration references in an older form that Terraform v1.0 and later don't support anymore.

    For your immediate work I'd suggest just figuring out which Terraform version this configuration's associated state was created by and using the latest patch release of that version to do your work, so you can avoid doing any immediate upgrade work. To do that, find your current Terraform state snapshot (refer to the backend configuration to see where it's stored), which will be a JSON data structure stored somewhere configured either in the Terraform configuration or in the Terragrunt configuration.

    In that JSON object there will be a top-level property called terraform_version which will map to a string like 0.11.2, or 0.12.3, or similar. Take the first two elements of that version number as the Terraform major release and then refer to the list of available versions and find the newest version with the same major release number. For example, if you found 0.11.2 in your state file then at the time of writing you'd select Terraform 0.11.15, because that's the newest release in the v0.11 series.

    You should then be able to use that version of Terraform to work with your current Terraform configuration and state.


    Once you know which version your configuration is currently expecting and you're ready to upgrade, you can consult the Terraform v1.0 upgrade guide to see the recommended steps to get from whatever version you are currently using to a version after the v1.0.0 release, after which you can select the latest v1.*.* moving forward because they are all subject to compatibility promises after that point.

    In particular, the v1.0 upgrade guide links to the earlier guide to move from v0.12 to v0.13, which includes steps to move beyond the error message you included in your question. (That is "the Terraform 0.13 upgrade process" that the error message is referring to.)