Skip to content

Instantly share code, notes, and snippets.

@ctrl-freak
Created May 11, 2022 05:10
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 ctrl-freak/0fc46b7c1b62d616cd1d3a2dd6c828bf to your computer and use it in GitHub Desktop.
Save ctrl-freak/0fc46b7c1b62d616cd1d3a2dd6c828bf to your computer and use it in GitHub Desktop.
Terraform Cloud Replace Provider in Remote State for 0.13 Upgrade

Background

When upgrading to Terraform 0.13 where runs driven by VCS and state is stored remotely (in this case Terraform Cloud)

I had an issue where a public Github module I was using included versions.tf which fails on older terraform versions.

I'd never used terraform locally, only connected the repository to Terraform Cloud.

The terraform 0.13upgrade is only in the 0.13 binaries, I had to download the old binary for my OS and run that specifically.

Even after running the upgrade command, the state still contained the old provider references.

Solution is to connect local terraform to cloud and replace provider.

Install terraform, Clone TF repository

To local location

Set Workspace version to newer

I don't know specifically when during this process it should be done.

Add Terraform block with Cloud

terraform {
  cloud {
    organization = "org-name"

    workspaces {
      name = "workspace-name"
    }
  }
}

Use 0.13 binary to upgrade Providers

https://releases.hashicorp.com/terraform

..\terraform 0.13upgrade

Init

terraform init

Resolve any issues connecting to Cloud

Replace Providers

terraform providers

$ terraform providers

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/aws] ~> 3.0
├── provider[registry.terraform.io/hashicorp/archive] 2.2.0
└── module.main
    └── provider[registry.terraform.io/hashicorp/aws] ~> 3.0

Providers required by state:

    provider[registry.terraform.io/-/archive]

    provider[registry.terraform.io/-/aws]

terraform state replace-provider registry.terraform.io/-/archive registry.terraform.io/hashicorp/archive

hashicorp/archive
Terraform will perform the following actions:

  ~ Updating provider:
    - registry.terraform.io/-/archive
    + registry.terraform.io/hashicorp/archive

Changing 3 resources:

  data.archive_file.zipExchangeTravelMoneyOz
  data.archive_file.zipStore
  data.archive_file.zipExchangeTravelex

Do you want to make these changes?
Only 'yes' will be accepted to continue.

Enter a value: yes

Successfully replaced provider for 3 resources.
Releasing state lock. This may take a few moments...

Triggering run from UI should then be successful, or give you useful errors to fix.

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