plugin: Make GetRuleConfigContent doesn't return an error even if config not found #1481
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, The
GetRuleConfigContent
returns an error when the passed rule config is not found. However, this behavior is inconvenient when callingDecodeRuleConfig
on rules with default config.If the rule config is not found, the rule should just adopt the default config, but
DecodeRuleConfig
will fail becauseGetRuleConfigContent
will return an error. In order to properly adopt the default config in this situation, you must correctly handle the "rule config not found" error returned byGetRuleConfigContent
.This PR changes the behavior of the
GetRuleConfigContent
API to simply return an empty body if the rule config is not found. This allows the caller ofDecodeRuleConfig
to not care whether the rule config exists.Be careful with the behavior when there are required attributes. It will behave like this:
--enable-rule
option.This behavior is expected to be guaranteed by E2E testing. This behavior is the same as the old
DecodeRuleConfig
:https://github.com/terraform-linters/tflint/blob/v0.39.3/tflint/runner.go#L391-L408