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

Null is not nothing, it’s a value that represents the absence of a value. When developing a Terraform module it’s important to understand the difference between null1 and other default values types for variables. Using null as the default value for optional 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 default2 value or omit it altogether, because it’s an optional3 variable. If omitted, it falls back to the API’s 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#default ↩︎

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

/null-is-not-nothing