While consolidating a handful of my sites from various hosting providers, I wanted to add those domains to my Cloudflare account to protect them from malicious traffic & improve their performance.
At the time this post was written, 0.14 is the latest version – but I was still on v0.12 which I had installed with a simple brew install terraform
command. As I typically do, I ran brew update && brew upgrade
and voila! I was on the latest version, having skipped v0.13:
$ terraform version
Terraform v0.14.3
However, I learned the hard way that Terraform only supports upgrading to each release in order, and they don’t recommend skipping versions. If you are upgrading from earlier versions, it is extremely important to follow the Upgrade Guides!
Here’s a couple examples of the issues I encountered …
Error: Failed to query available provider packages
Upon skipping the 0.13 major release, I found that third-party Terraform providers (those developed by various cloud providers, not by Hashicorp) were no longer working.
So after upgrading Terraform & adding the Cloudflare provider block, I typed terraform init
in my new project and got the following error:
$ terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/cloudflare...
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
hashicorp/cloudflare: provider registry registry.terraform.io does not have a
provider named registry.terraform.io/hashicorp/cloudflare
If you have just upgraded directly from Terraform v0.12 to Terraform v0.14
then please upgrade to Terraform v0.13 first and follow the upgrade guide for
that release, which might help you address this problem.
Did you intend to use cloudflare/cloudflare? If so, you must specify that
source address in each module which requires that provider. To see which
modules are currently depending on hashicorp/cloudflare, run the following
command:
terraform providers
Notice that penultimate paragraph about upgrading directly from v0.12 to v0.14? It’s great that Hashicorp built such a helpful error message into their CLI, and following it solved my issues completely. However, I’d strongly prefer fewer breaking changes, or better tools/codemods to help users update directly to later versions without the friction of upgrading to each release in between.
Looking at the 0.12 → 0.13 Upgrade Guide, you’ll notice a section about Explicit Provider Source Locations which describes the new hierarchical namespace structure for providers. My existing hashicorp/cloudflare
provider no longer existed, because the Cloudflare provider is not published by hashicorp
– the new name is cloudflare/cloudflare
, and it must be in the required_providers
nested block inside the terraform
configuration block.
So I created a new main.tf
file and added the appropriate provider config:
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 2.0"
}
}
}
Notice the version
argument, which I added to ensure I’m using the latest
Warning: Interpolation-only expressions are deprecated
I also received a deprecation warning upon running terraform init
in my new project.
Here’s what that warning looked like:
$ terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/cloudflare...
Warning: Interpolation-only expressions are deprecated
on cloudflare.tf line 11, in resource "cloudflare_record" "www":
11: domain = "${var.domain}"
Terraform 0.11 and earlier required all non-constant expressions to be
provided via interpolation syntax, but this pattern is now deprecated. To
silence this warning, remove the "${ sequence from the start and the }"
sequence from the end of this expression, leaving just the inner expression.
Template interpolation syntax is still used to construct strings from
expressions when the template includes multiple interpolation sequences or a
mixture of literal strings and interpolations. This deprecation applies only
to templates that consist entirely of a single interpolation sequence.
This warning is telling me that using interpolation syntax, e.g., ${someVar.someThing}
, is no longer supported. Just remove the bracket syntax and leave the inner expression, and you’re good to go.
Conclusion
There were a few other issues I ran into, but they were easily solvable with Startpage & Stack Overflow.
I’m out of time for writing this week, so best of luck to ya!