Chapter 4. Built-In Fields: Reference Attributes, Local Values, Meta-Arguments, and Outputs
In Chapter 2, you saw the various ways to construct and assign input variables in TF. In this chapter, we’ll build on this premise, and you’ll see the other elements that may hold a value in TF, how to effectively construct them, and how they may be leveraged strategically to enhance flexibility, readability, and maintainability of TF projects. You’ll also learn the meta-arguments and the dynamic{} block, which are both used to further augment flexibility and, more importantly, how to introduce them tactically.
Resource Fields and Reference Attributes
Similar to input variables for modules, the resource fields are the input elements for a resource{} block. They’re defined by the provider and generally map to parameters expected by the corresponding API that’s exposed by the CSP. It’s common for most resource fields to be optional, with default values (that are sometimes null) in many cases. For example, a general purpose storage bucket may support dozens of first-order resource fields, but require only two, as shown in Example 4-1.
Example 4-1. Using only the required resource fields to establish a Google Cloud Storage bucket
resource "google_storage_bucket" "simplest" {
name = "simplest-bucket-configuration"
location = "US"
}
In addition to resource fields, TF supports another resource component, the reference attribute, which will be assigned informational data as values by the CSP. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access