Wednesday, October 4, 2023

Terraform Google provider adds updates to default labels

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.

2023 Terraform Google provider highlights

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:

  • Label enhancements
  • Allowing Terraform plans to include provider-default values
  • Other changes and deprecations

Default label enhancements

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 attribute: Resources will be expected to manage only user-set labels, and are no longer authoritative over all labels in Google Cloud.
  • Terraform labels: A new output-only attribute added to all resources, where the value contains all labels either set directly on the resource (via labels) or added by default (from default_labels)
  • Effective labels: A new output-only attribute added to all resources, where the value contains a combination of all labels set on the resource in the Terraform configuration and any other labels present on the resource in Google Cloud that aren’t managed via Terraform.

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" }

Improvements that let Terraform plans include provider default values

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.

Removing deprecated attributes and other behavior changes

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.

Key benefits of Terraform Google provider version 5.0

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:

  • Increase productivity: Application developers can now set labels that will automatically be applied to all resources. This improves the user experience and simplifies practitioner configurations.
  • Reduce risk: With the default enhancements, platform teams now have increased visibility into their infrastructure, significantly reducing the time and customization it takes to support those new capabilities.

Learn more about Google Cloud and HashiCorp

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.



from HashiCorp Blog https://bit.ly/45dbW61
via IFTTT

No comments:

Post a Comment