Skip to content

Report & generate missing type constraint in variable block #1476

Open
@radeksimko

Description

@radeksimko

Context

Users may - and anecdotally often do - write configuration without considering the type of variables, for example:

variable "foo" {
}

Sometimes they go one step further but still not very far by defining the type as any:

variable "foo" {
  type = any
}

or they may let the type to be inferred from the default value, e.g.

variable "foo" {
  default = []
}

In all these cases, they can introduce bugs due to type mismatches/conversions or at least make it much more difficult for collaborators and consumers of the module to understand the module as a whole.

Proposal

  • Raise missing type constraint as a warning diagnostic, suggesting that types are better declared explicitly to communicate intentions
  • Raise type = any as informal diagnostic, suggesting more concrete type, to communicate intentions
  • Provide quickfix code action to generate type based on default value

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions