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

Null Is Not Nothing


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. ↩︎

  2. ↩︎

  3. ↩︎