You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
use default = null instead of default = "" in variables where possible #755
good idea, we can make the lint and then proceed to fix it, we will have to be careful to edit the associated ternary statements though (there's var.something != "" ? var.something : "" everywhere)
we should also consider switching to try(var.something, "") instead, it is cleaner.
(there is also coalesce, but we can't use it for a fallback to an empty string because coalesce takes any number of arguments and returns the first one that isn't null or an empty string.)
for example:
url = join("", [
var.protocol,
"://coder.coder-remote/open",
"?owner=",
data.coder_workspace_owner.me.name,
"&workspace=",
data.coder_workspace.me.name,
- var.folder != "" ? join("", ["&folder=", var.folder]) : "",+ # this would be fine, because passing "&folder=" if the folder variable is empty or null then that works+ join("", ["&folder=", try(var.folder, "")]),
var.open_recent ? "&openRecent" : "",
"&url=",
data.coder_workspace.me.access_url,
"&token=$SESSION_TOKEN",
])
Activity
matifali commentedon Feb 24, 2026
@DevelopmentCats and I recently discussed this and even considered adding a lint rule to prevent it.
phorcys420 commentedon Feb 24, 2026
good idea, we can make the lint and then proceed to fix it, we will have to be careful to edit the associated ternary statements though (there's
var.something != "" ? var.something : ""everywhere)we should also consider switching to
try(var.something, "")instead, it is cleaner.(there is also
coalesce, but we can't use it for a fallback to an empty string becausecoalescetakes any number of arguments and returns the first one that isn't null or an empty string.)for example:
url = join("", [ var.protocol, "://coder.coder-remote/open", "?owner=", data.coder_workspace_owner.me.name, "&workspace=", data.coder_workspace.me.name, - var.folder != "" ? join("", ["&folder=", var.folder]) : "", + # this would be fine, because passing "&folder=" if the folder variable is empty or null then that works + join("", ["&folder=", try(var.folder, "")]), var.open_recent ? "&openRecent" : "", "&url=", data.coder_workspace.me.access_url, "&token=$SESSION_TOKEN", ])there are also other ways we could just handle
nullcases better since it isnulland not an empty string.some good examples here: https://www.codeterraform.com/post/successfully-deal-with-terraforms-null-value
refactor(vault-cli): use default = null instead of default = "" for v…