Version 5.0 of the HashiCorp Terraform Google provider brings improvements to default labels, allowing practitioners to set labels at the provider level.
We are excited to announce the release of version 5.0 of the Terraform Google provider with highly anticipated updates to labels, designed to increase productivity and reduce risk. Default labels can now be set at the provider level, which applies them across all resources that support them in the configuration. This post reviews the details and benefits of this updated feature, as well as a handful of other new features released this year.
As the Terraform Google provider’s download count tops 185 million downloads this year, Google and HashiCorp continue to develop new integrations to help customers work faster, get the benefits from more services and features, and find developer-friendly ways to deploy cloud infrastructure. This year, we focused on listening to the community by adding oft-requested new features to the Google provider, including:
Default labels in the Google provider allow practitioners to define common metadata labels at the provider level. These labels are then applied to all supported resources in the Terraform configuration. Previously, assumptions and restrictions were made to allow this feature to function across as many resources as possible. However, it could be difficult to retrofit existing code, causing frustrating manual intervention. The community has now expressed a desire for the ability to define a default set of labels on the provider that would be applied to all resources using that provider.
New features available in the Terraform provider SDK and Plugin framework have removed several limitations that made labels difficult to integrate with existing resources and modules. Now users are able to move default information from apply time, where it’s unknown at plan time, to plan time. This removes the misleading sticky behavior of the values, and provides users additional information at plan time. So now, the provider has been updated to include a default_labels
field and the labels defined on the provider will now be applied automatically to all resources.
The updates in version 5.0 resources include:
labels
) or added by default (from default_labels
)This example shows how default labels can be used to apply metadata to a Terraform configuration:
provider "google" { project = "my-project" default_labels = { label-A = "I'm a default label from the provider" }} resource "google_pubsub_topic" "example" { name = "example-topic" labels = { label-B = "I'm a label set in the resource block" } message_retention_duration = "86600s"}
Previously, any default values set in the provider configuration were available only at apply
time. This meant that Terraform plans could not indicate what values would be used, and instead displayed a placeholder (known after apply)
value. However, beginning in version 5.0 of the Google provider, Terraform plans will reliably show any default values that are in use, resulting in more clarity when teams review planned changes to their infrastructure.
This new feature will also improve handling of default projects by enabling teams to write the default project value into the new state when project information is unset at the resource-level. This will override old values and remove the previous sticky behavior.
This major release will also remove attributes marked as deprecated in previous versions. Typically, these were marked as such due to changes in the upstream API, or in some cases, the use of the attribute causes confusion.We removed attributes and features marked as deprecated in accordance with our best practices for provider development.
In addition, we introduced several behavior changes aimed at improving usability by updating how we handle 404 errors, standardizing location-based logic, and adding multi-file support for Google endpoints service.
The release of version 5.0 of the Terraform Google provider allows practitioners to more efficiently manage labels for the provider. Here are the two main benefits of this new release:
To learn the basics of Terraform using the Google provider, check out the Get Started tutorials for Google Cloud.
When upgrading to version 5.0 of the Terraform Google provider, please consult the upgrade guide on the Terraform Registry, which contains a full list of the changes and upgrade considerations. Because this release introduces breaking changes, we recommend pinning your provider version to protect against unexpected results. For a complete list of the changes in 5.0, please refer to the Google provider changelog.
HashiCorp and Google partner on cloud infrastructure to make it easy for users to provision and manage Google Cloud resources. You can find out more about our partnership on the Google Cloud partner page.
If you are currently using Terraform Community or are completely new to Terraform, sign up for Terraform Cloud and get started using the Free offering today.
HCP Terraform and Terraform Enterprise enhance permissions management capabilities to eliminate the bottleneck of relying solely on the owner for managing teams.
ServiceNow Service Catalog for Terraform now lets users provision infrastructure powered by no-code modules published in their organization’s private registry.
No-code provisioning module version upgrades are now GA in HCP Terraform, providing validated self-service infrastructure to reduce toil and lower cloud spend.