-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider_missing_default_tags: correctly handle unknown values #851
base: master
Are you sure you want to change the base?
Conversation
@@ -141,7 +140,8 @@ func (r *AwsProviderMissingDefaultTagsRule) Check(runner tflint.Runner) error { | |||
}, nil) | |||
|
|||
if err != nil { | |||
return nil | |||
logger.Warn("Could not evaluate tags, skipping %s.%s.%s.%s: %s", provider.Labels[0], providerAlias, providerDefaultTagsBlockName, providerTagsAttributeName, err) | |||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that feedback may be lost in case of simple evaluation errors (e.g. undefined variables), would it be better to only short circuit in the tflint.ErrUnknownValue
case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is an option, that's what I did originally. Ignoring null variable values would be a separate case. What do you think about erroring there, versus trying to ignore it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think unknown and null values should be ignored, but other errors should not be ignored. How about the following?
if errors.Is(err, tflint.ErrUnknownValue) {
logger.Warn("Could not evaluate tags, skipping %s.%s.%s.%s: %s", provider.Labels[0], providerAlias, providerDefaultTagsBlockName, providerTagsAttributeName, err)
continue
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In spirit I agree, but the null case comes in as a raw diagnostic and not a wrapped/simple error:
Fixes a bug where
provider_missing_default_tags
does not correctly handle unknown tags. Adds the missing test coverage and then fixes the failing tests by correcting the control flow for unknown values.Cases
Unknown
The incorrect flow:
Doing this inside the
EvaluateExpr
callback effectively ignores the value and leavesproviderTags
empty before checking for unset tags. Instead, unknown values need to short circuit the comparison. So I've returned an error, borrowingtflint.UnknownError
.Null
The multiple cases where errors are silently discarded was a red flag:
Now, all errors are returned except evaluation errors of the
tags
attribute. This could be due to an explicit unknown value error or it could be a null value. As in:This is technically not valid configuration, as
var.tag
isnull
, andnull
is not a valid map key. We could just return this error and insist users pass a variable value to TFLint or set a default to make the configuration valid. I initially went that path.But for the sake of backward compatibility, any error will short circuit checking (as before). But now, the warning log happens outside of the
EvalauteExpr
callback, for all errors, such that they are no longer wholly silent. If the rule is skipping a tag map because of a null key error, it will print that error in a warning.Related
Closes #850