github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/terraformrules/terraform_deprecated_interpolation.go (about) 1 package terraformrules 2 3 import ( 4 "log" 5 6 "github.com/hashicorp/hcl/v2" 7 "github.com/hashicorp/hcl/v2/hclsyntax" 8 "github.com/terraform-linters/tflint/tflint" 9 ) 10 11 // TerraformDeprecatedInterpolationRule warns of deprecated interpolation in Terraform v0.11 or earlier. 12 type TerraformDeprecatedInterpolationRule struct{} 13 14 // NewTerraformDeprecatedInterpolationRule return a new rule 15 func NewTerraformDeprecatedInterpolationRule() *TerraformDeprecatedInterpolationRule { 16 return &TerraformDeprecatedInterpolationRule{} 17 } 18 19 // Name returns the rule name 20 func (r *TerraformDeprecatedInterpolationRule) Name() string { 21 return "terraform_deprecated_interpolation" 22 } 23 24 // Enabled returns whether the rule is enabled by default 25 func (r *TerraformDeprecatedInterpolationRule) Enabled() bool { 26 return true 27 } 28 29 // Severity returns the rule severity 30 func (r *TerraformDeprecatedInterpolationRule) Severity() string { 31 return tflint.WARNING 32 } 33 34 // Link returns the rule reference link 35 func (r *TerraformDeprecatedInterpolationRule) Link() string { 36 return tflint.ReferenceLink(r.Name()) 37 } 38 39 // Check emits issues on the deprecated interpolation syntax. 40 // This logic is equivalent to the warning logic implemented in Terraform. 41 // See https://github.com/hashicorp/terraform/pull/23348 42 func (r *TerraformDeprecatedInterpolationRule) Check(runner *tflint.Runner) error { 43 if !runner.TFConfig.Path.IsRoot() { 44 // This rule does not evaluate child modules. 45 return nil 46 } 47 48 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 49 50 return runner.WalkExpressions(func(expr hcl.Expression) error { 51 r.checkForDeprecatedInterpolationsInExpr(runner, expr) 52 return nil 53 }) 54 } 55 56 func (r *TerraformDeprecatedInterpolationRule) checkForDeprecatedInterpolationsInExpr(runner *tflint.Runner, expr hcl.Expression) { 57 if _, ok := expr.(*hclsyntax.TemplateWrapExpr); !ok { 58 return 59 } 60 61 runner.EmitIssue( 62 r, 63 "Interpolation-only expressions are deprecated in Terraform v0.12.14", 64 expr.Range(), 65 ) 66 67 return 68 }