Skip to content

use default = null instead of default = "" in variables where possible #755

Open

Description

@phorcys420

a lot of our modules have default = "" variables instead of default = null, i think this is a bad practice and makes code less understandable.

Image

Activity

  1. matifali commented on Feb 24, 2026

    @matifali
    Member

    @DevelopmentCats and I recently discussed this and even considered adding a lint rule to prevent it.

  2. added theissue type on Feb 24, 2026
  3. phorcys420 commented on Feb 24, 2026

    @phorcys420
    MemberAuthor

    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",
      ])

    there are also other ways we could just handle null cases better since it is null and not an empty string.
    some good examples here: https://www.codeterraform.com/post/successfully-deal-with-terraforms-null-value

  4. self-assigned this
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions