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

Null Is Not Nothing

in
writing
date
4/21/2024

Null is not nothing.

It’s a value type1 in Terraform who’s never invited to the party but always seems to show up. Instead, I would encourage you to start inviting them, to the module party.

Null is not nothing, it is a value that represent the absence of a value. Making it the perfect default value for your input variables.

When an input variable of your module isn’t set, Terraform will fall back on the provider’s default for that optional2 attribute, or the upstream API’s default, if one exists.

Any default3 value for an input variable, other than null, is a value you have to maintain.

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