defaults
for terraform_remote_state
data source outputs
#175
Replies: 1 comment
-
It's an interesting thought but not equivalent and unlikely to be something we'd pursue. Here's why. The things we can detect as unused like resources and even Terraform/HCL also has expressions, which represent evaluation, often only fully possible at runtime. Importantly, jsonencode(locals) Detecting unused config depends on these structural keywords like The Take this example: output "remote_state" {
value = data.terraform_remote_state.foo.outputs
} Or this: output "foo" {
value = data.terraform_remote_state.foo.outputs[data.terraform_remote_state.foo.outputs.foo_key]
} Even for the cases that are theoretically statically resolvable you'll also need a lower level HCL strategy. With keywords you can easily get the references from an expression, at a Terraform language level: But with expressions you'd have to visit every expression that references the remote state object and go through the If you want to take a stab at a PR I'd be happy to help via review but given the high complexity and low payoff this won't be a priority otherwise. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
terraform_remote_state
data source has adefaults
attribute that sets default values for outputs, in case the state file is empty or lacks a required output.Suggestion
Since there are rules for unused locals, variables, and data sources, there just as well might be a rule that indicates values in
defaults
without the respective output.In addition, it'd be great to have an opt-in rule that requires a default for every output in use.
Example
Linting
should result in
Beta Was this translation helpful? Give feedback.
All reactions