Skip to content

Commit

Permalink
fix all integrated errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Jan 26, 2024
1 parent e6fb243 commit 35c8151
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ build:

install: build
mkdir -p ~/.tflint.d/plugins
mv ./tflint-ruleset-template ~/.tflint.d/plugins
mv ./tflint-ruleset-avm ~/.tflint.d/plugins
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
func main() {
plugin.Serve(&plugin.ServeOpts{
RuleSet: &tflint.BuiltinRuleSet{
Name: "template",
Name: "avm",
Version: version,
Rules: rules.Rules,
},
Expand Down
47 changes: 14 additions & 33 deletions rules/rule_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,22 @@ import (
azurerm "github.com/Azure/tflint-ruleset-azurerm-ext/rules"
basic "github.com/Azure/tflint-ruleset-basic-ext/rules"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
terraform "github.com/terraform-linters/tflint-ruleset-terraform/rules"
)

var Rules = []tflint.Rule{
Wrap(terraform.NewTerraformCommentSyntaxRule()),
Wrap(terraform.NewTerraformDeprecatedIndexRule()),
Wrap(terraform.NewTerraformDeprecatedInterpolationRule()),
Wrap(terraform.NewTerraformDeprecatedLookupRule()),
Wrap(terraform.NewTerraformDocumentedOutputsRule()),
Wrap(terraform.NewTerraformDocumentedVariablesRule()),
Wrap(terraform.NewTerraformEmptyListEqualityRule()),
Wrap(terraform.NewTerraformModulePinnedSourceRule()),
Wrap(terraform.NewTerraformModuleVersionRule()),
Wrap(terraform.NewTerraformNamingConventionRule()),
Wrap(terraform.NewTerraformRequiredProvidersRule()),
Wrap(terraform.NewTerraformRequiredVersionRule()),
Wrap(terraform.NewTerraformStandardModuleStructureRule()),
Wrap(terraform.NewTerraformTypedVariablesRule()),
Wrap(terraform.NewTerraformUnusedDeclarationsRule()),
Wrap(terraform.NewTerraformUnusedRequiredProvidersRule()),
Wrap(terraform.NewTerraformWorkspaceRemoteRule()),

Wrap(basic.NewTerraformHeredocUsageRule()),
Wrap(basic.NewTerraformModuleProviderDeclarationRule()),
Wrap(basic.NewTerraformOutputSeparateRule()),
Wrap(basic.NewTerraformRequiredProvidersDeclarationRule()),
Wrap(basic.NewTerraformRequiredVersionDeclarationRule()),
Wrap(basic.NewTerraformSensitiveVariableNoDefaultRule()),
Wrap(basic.NewTerraformVariableNullableFalseRule()),
Wrap(basic.NewTerraformVariableSeparateRule()),

Wrap(azurerm.NewAzurermResourceTagRule()),

NewTerraformDotTfRule(),
}
var Rules = func() []tflint.Rule {
return []tflint.Rule{
Wrap(basic.NewTerraformHeredocUsageRule()),
Wrap(basic.NewTerraformModuleProviderDeclarationRule()),
Wrap(basic.NewTerraformOutputSeparateRule()),
Wrap(basic.NewTerraformRequiredProvidersDeclarationRule()),
Wrap(basic.NewTerraformRequiredVersionDeclarationRule()),
Wrap(basic.NewTerraformSensitiveVariableNoDefaultRule()),
Wrap(basic.NewTerraformVariableNullableFalseRule()),
Wrap(basic.NewTerraformVariableSeparateRule()),
Wrap(azurerm.NewAzurermResourceTagRule()),
NewTerraformDotTfRule(),
}
}()

type wrappedRule struct {
tflint.Rule
Expand Down
4 changes: 4 additions & 0 deletions rules/terraform_tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"strings"
)

var _ tflint.Rule = new(TerraformDotTfRule)
Expand Down Expand Up @@ -35,6 +36,9 @@ func (t *TerraformDotTfRule) Severity() tflint.Severity {
func (t *TerraformDotTfRule) Check(r tflint.Runner) error {
tFile, err := r.GetFile("terraform.tf")
if err != nil {
if strings.Contains(err.Error(), "file not found") {
return r.EmitIssue(t, "All avm Terraform modules must contain `terraform.tf` file", hcl.Range{})
}
return err
}
if tFile == nil {
Expand Down
8 changes: 8 additions & 0 deletions rules/terraform_tf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func TestTerraformTf(t *testing.T) {
expectIssue: true,
expectedMessage: "must contain `terraform.tf` file",
},
{
desc: "NoTerraformDotTfFileShouldEmitIssue2",
files: map[string]string{
"main.tf": "",
},
expectIssue: true,
expectedMessage: "must contain `terraform.tf` file",
},
{
desc: "NoTerraformBlockInTerraformDotTfFileShouldEmitError",
files: map[string]string{
Expand Down

0 comments on commit 35c8151

Please sign in to comment.