Add a rule to catch when typed object arguments to modules provide extra keys #203
DanDanN00dle
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
This seems like something worth considering, but it's debatable in which cases it should be flagged or not. Another challenge is that the current SDK does not have an API to get the variable definitions of a module, so we have to tackle that first. Moreover, remote modules are not always accessible, so there is a possibility that some module calls may not be detected correctly. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Introduction
In terraform, the parser will quietly coerce arguments to a module that uses
object
-typed parameters to the target type by discarding extra keys. The rationale being that this reduces friction & dependency-hell between modules when one module takes an input generated as an output from another module. However, when the argument is generated in the root terraform or provided as a literal, discarding a key generally signals a miscommunication or incompatibility with a new module version. Worse, it may just be a misspelling of the object key.Proposal
Given a terraform configuration with a module that defines a variable of type 'object'
When the terraform provides a map/object literal and that literal contains a key that is not specified in the declared module type structure,
Then tflint will flag this as an error.
Ideally this will also flag:
An example of this is:
amodule/variables.tf
:main.tf
: (root terraform configuration)Currently, terraform silently ignores
a.key2
, we are proposing that tflint will highlight this error.References
Corresponding terraform issue
Documentation on lossy map -> object conversions
Beta Was this translation helpful? Give feedback.
All reactions