Bruno Schaatsbergen website Mastodon PGP Key email A drawing of an astronaut in space The Netherlands

Null Is Not Nothing

in
blog
date
4/21/2024

In Terraform, null is not nothing; it is a value that represents the absence of a value. When creating a Terraform module it’s important to understand the difference between null1 and default values for variables. Using null as the default value for optional2 variables is a good practice. This way, if the variable isn’t set, it won’t be passed down to a resource. This allows the resource provider to use its own internal default3 value or omit it altogether. If the optional variable is omitted, it falls back to the resource provider’s API default value.

variable "example" {
  type    = string
  default = null
}

👟 Footnotes

  1. https://developer.hashicorp.com/terraform/language/expressions/types#null ↩︎

  2. https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#optional ↩︎

  3. https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#default ↩︎

/null-is-not-nothing