github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/terraformrules/terraform_deprecated_interpolation_test.go (about) 1 package terraformrules 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/hcl/v2" 7 "github.com/terraform-linters/tflint/tflint" 8 ) 9 10 func Test_TerraformDeprecatedInterpolationRule(t *testing.T) { 11 cases := []struct { 12 Name string 13 Content string 14 Expected tflint.Issues 15 }{ 16 { 17 Name: "deprecated single interpolation", 18 Content: ` 19 resource "null_resource" "a" { 20 triggers = "${var.triggers}" 21 }`, 22 Expected: tflint.Issues{ 23 { 24 Rule: NewTerraformDeprecatedInterpolationRule(), 25 Message: "Interpolation-only expressions are deprecated in Terraform v0.12.14", 26 Range: hcl.Range{ 27 Filename: "config.tf", 28 Start: hcl.Pos{Line: 3, Column: 13}, 29 End: hcl.Pos{Line: 3, Column: 30}, 30 }, 31 }, 32 }, 33 }, 34 { 35 Name: "deprecated single interpolation in provider block", 36 Content: ` 37 provider "null" { 38 foo = "${var.triggers["foo"]}" 39 }`, 40 Expected: tflint.Issues{ 41 { 42 Rule: NewTerraformDeprecatedInterpolationRule(), 43 Message: "Interpolation-only expressions are deprecated in Terraform v0.12.14", 44 Range: hcl.Range{ 45 Filename: "config.tf", 46 Start: hcl.Pos{Line: 3, Column: 8}, 47 End: hcl.Pos{Line: 3, Column: 32}, 48 }, 49 }, 50 }, 51 }, 52 { 53 Name: "deprecated single interpolation in locals block", 54 Content: ` 55 locals { 56 foo = "${var.triggers["foo"]}" 57 }`, 58 Expected: tflint.Issues{ 59 { 60 Rule: NewTerraformDeprecatedInterpolationRule(), 61 Message: "Interpolation-only expressions are deprecated in Terraform v0.12.14", 62 Range: hcl.Range{ 63 Filename: "config.tf", 64 Start: hcl.Pos{Line: 3, Column: 8}, 65 End: hcl.Pos{Line: 3, Column: 32}, 66 }, 67 }, 68 }, 69 }, 70 { 71 Name: "deprecated single interpolation in nested block", 72 Content: ` 73 resource "null_resource" "a" { 74 provisioner "local-exec" { 75 single = "${var.triggers["greeting"]}" 76 } 77 }`, 78 Expected: tflint.Issues{ 79 { 80 Rule: NewTerraformDeprecatedInterpolationRule(), 81 Message: "Interpolation-only expressions are deprecated in Terraform v0.12.14", 82 Range: hcl.Range{ 83 Filename: "config.tf", 84 Start: hcl.Pos{Line: 4, Column: 12}, 85 End: hcl.Pos{Line: 4, Column: 41}, 86 }, 87 }, 88 }, 89 }, 90 { 91 Name: "interpolation as template", 92 Content: ` 93 resource "null_resource" "a" { 94 triggers = "${var.triggers} " 95 }`, 96 Expected: tflint.Issues{}, 97 }, 98 { 99 Name: "interpolation in array", 100 Content: ` 101 resource "null_resource" "a" { 102 triggers = ["${var.triggers}"] 103 }`, 104 Expected: tflint.Issues{}, 105 }, 106 { 107 Name: "new interpolation syntax", 108 Content: ` 109 resource "null_resource" "a" { 110 triggers = var.triggers 111 }`, 112 Expected: tflint.Issues{}, 113 }, 114 } 115 116 rule := NewTerraformDeprecatedInterpolationRule() 117 118 for _, tc := range cases { 119 runner := tflint.TestRunner(t, map[string]string{"config.tf": tc.Content}) 120 121 if err := rule.Check(runner); err != nil { 122 t.Fatalf("Unexpected error occurred: %s", err) 123 } 124 125 tflint.AssertIssues(t, tc.Expected, runner.Issues) 126 } 127 }