Terraform — Optional Values (Update)

Daniel Randell
2 min readJun 26, 2022

--

I wrote this article about Terraform and its experimental support for optional variables a while back.

The good news is that this is finally coming in Terraform 1.3.0!

You can view the changelog for the feature and its documentation over on Terraforms GitHub release page.

But for a quick recap, the Terraform Optional support allows you to specify an optional variable inside an object type. But now you can also specify a default value in the optional inside of them just becoming null!

variable "with_optional_attribute" {
type = object({
a = string # a required attribute
b = optional(string) # an optional attribute
c = optional(number, 127) # an optional attribute with a default value
})
}

I first wrote the initial article on this experimental support just under a year ago so it’s nice to see this finally making its way into the GA builds!

If you’d like to provide feedback on this feature, there’s a forum post requesting just that here.

Disclaimer: This is still in alpha and although unlikely to change I would still recommend not using this in production workloads just yet. We had to wait four months between Tf 1.1 and 1.2, so likely this should make its way into GA around September time if not sooner.

--

--

Daniel Randell
Daniel Randell

No responses yet