github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/terraformrules/terraform_documented_outputs.go (about)

     1  package terraformrules
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  
     7  	"github.com/terraform-linters/tflint/tflint"
     8  )
     9  
    10  // TerraformDocumentedOutputsRule checks whether outputs have descriptions
    11  type TerraformDocumentedOutputsRule struct{}
    12  
    13  // NewTerraformDocumentedOutputsRule returns a new rule
    14  func NewTerraformDocumentedOutputsRule() *TerraformDocumentedOutputsRule {
    15  	return &TerraformDocumentedOutputsRule{}
    16  }
    17  
    18  // Name returns the rule name
    19  func (r *TerraformDocumentedOutputsRule) Name() string {
    20  	return "terraform_documented_outputs"
    21  }
    22  
    23  // Enabled returns whether the rule is enabled by default
    24  func (r *TerraformDocumentedOutputsRule) Enabled() bool {
    25  	return false
    26  }
    27  
    28  // Severity returns the rule severity
    29  func (r *TerraformDocumentedOutputsRule) Severity() string {
    30  	return tflint.NOTICE
    31  }
    32  
    33  // Link returns the rule reference link
    34  func (r *TerraformDocumentedOutputsRule) Link() string {
    35  	return tflint.ReferenceLink(r.Name())
    36  }
    37  
    38  // Check checks whether outputs have descriptions
    39  func (r *TerraformDocumentedOutputsRule) Check(runner *tflint.Runner) error {
    40  	if !runner.TFConfig.Path.IsRoot() {
    41  		// This rule does not evaluate child modules.
    42  		return nil
    43  	}
    44  
    45  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    46  
    47  	for _, output := range runner.TFConfig.Module.Outputs {
    48  		if output.Description == "" {
    49  			runner.EmitIssue(
    50  				r,
    51  				fmt.Sprintf("`%s` output has no description", output.Name),
    52  				output.DeclRange,
    53  			)
    54  		}
    55  	}
    56  
    57  	return nil
    58  }