Skip to content

Commit

Permalink
deprecated_interpolations: evaluate all block types/expressions (#849)
Browse files Browse the repository at this point in the history
* deprecated_interpolations: evaluate all expressions
* fix deprecated interpolation in integration test
  • Loading branch information
bendrucker committed Jul 21, 2020
1 parent 9538f05 commit df63b3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions integration/without_module_init/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ variable "instance_type" {
module "instances" {
source = "./module"

unknown = "${var.unknown}"
instance_type = "${var.instance_type}"
unknown = var.unknown
instance_type = var.instance_type
}
29 changes: 4 additions & 25 deletions rules/terraformrules/terraform_deprecated_interpolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,10 @@ func (r *TerraformDeprecatedInterpolationRule) Link() string {
func (r *TerraformDeprecatedInterpolationRule) Check(runner *tflint.Runner) error {
log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())

for _, resource := range runner.TFConfig.Module.ManagedResources {
r.checkForDeprecatedInterpolationsInBody(runner, resource.Config)
}
for _, provider := range runner.TFConfig.Module.ProviderConfigs {
r.checkForDeprecatedInterpolationsInBody(runner, provider.Config)
}

return nil
}

func (r *TerraformDeprecatedInterpolationRule) checkForDeprecatedInterpolationsInBody(runner *tflint.Runner, body hcl.Body) {
nativeBody, ok := body.(*hclsyntax.Body)
if !ok {
return
}

for _, attr := range nativeBody.Attributes {
r.checkForDeprecatedInterpolationsInExpr(runner, attr.Expr)
}

for _, block := range nativeBody.Blocks {
r.checkForDeprecatedInterpolationsInBody(runner, block.Body)
}

return
return runner.WalkExpressions(func(expr hcl.Expression) error {
r.checkForDeprecatedInterpolationsInExpr(runner, expr)
return nil
})
}

func (r *TerraformDeprecatedInterpolationRule) checkForDeprecatedInterpolationsInExpr(runner *tflint.Runner, expr hcl.Expression) {
Expand Down
18 changes: 18 additions & 0 deletions rules/terraformrules/terraform_deprecated_interpolation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ resource "null_resource" "a" {
Content: `
provider "null" {
foo = "${var.triggers["foo"]}"
}`,
Expected: tflint.Issues{
{
Rule: NewTerraformDeprecatedInterpolationRule(),
Message: "Interpolation-only expressions are deprecated in Terraform v0.12.14",
Range: hcl.Range{
Filename: "config.tf",
Start: hcl.Pos{Line: 3, Column: 8},
End: hcl.Pos{Line: 3, Column: 32},
},
},
},
},
{
Name: "deprecated single interpolation in locals block",
Content: `
locals {
foo = "${var.triggers["foo"]}"
}`,
Expected: tflint.Issues{
{
Expand Down

0 comments on commit df63b3e

Please sign in to comment.