mirror of https://github.com/hashicorp/terraform
These interpolations are removed when upgrading using 0.12upgrade, and are removed in terraform fmt in many casespull/27835/head
parent
3da5d2bdf6
commit
fa7c3d7e10
@ -1,61 +0,0 @@
|
||||
package configs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
"github.com/hashicorp/hcl/v2/hclsyntax"
|
||||
)
|
||||
|
||||
func TestWarnForDeprecatedInterpolationsInExpr(t *testing.T) {
|
||||
tests := []struct {
|
||||
Expr string
|
||||
WantSubstr string
|
||||
}{
|
||||
{
|
||||
`"${foo}"`,
|
||||
"leaving just the inner expression",
|
||||
},
|
||||
{
|
||||
`{"${foo}" = 1}`,
|
||||
// Special message for object key expressions, because just
|
||||
// removing the interpolation markers would change the meaning
|
||||
// in that context.
|
||||
"opening and closing parentheses respectively",
|
||||
},
|
||||
{
|
||||
`{upper("${foo}") = 1}`,
|
||||
// But no special message if the template is just descended from an
|
||||
// object key, because the special interpretation applies only to
|
||||
// a naked reference in te object key position.
|
||||
"leaving just the inner expression",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.Expr, func(t *testing.T) {
|
||||
expr, diags := hclsyntax.ParseExpression([]byte(test.Expr), "", hcl.InitialPos)
|
||||
if diags.HasErrors() {
|
||||
t.Fatalf("parse error: %s", diags.Error())
|
||||
}
|
||||
|
||||
diags = warnForDeprecatedInterpolationsInExpr(expr)
|
||||
if !diagWarningsContainSubstring(diags, test.WantSubstr) {
|
||||
t.Errorf("wrong warning message\nwant detail substring: %s\ngot: %s", test.WantSubstr, diags.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func diagWarningsContainSubstring(diags hcl.Diagnostics, want string) bool {
|
||||
for _, diag := range diags {
|
||||
if diag.Severity != hcl.DiagWarning {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(diag.Detail, want) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
# It's redundant to write an expression that is just a single template
|
||||
# interpolation with another expression inside, like "${foo}", but it
|
||||
# was required before Terraform v0.12 and so there are lots of existing
|
||||
# examples out there using that style.
|
||||
#
|
||||
# We are generating warnings for that situation in order to guide those
|
||||
# who are following old examples toward the new idiom.
|
||||
|
||||
variable "triggers" {
|
||||
type = "map" # WARNING: Quoted type constraints are deprecated
|
||||
}
|
||||
|
||||
provider "null" {
|
||||
foo = "${var.triggers["foo"]}" # WARNING: Interpolation-only expressions are deprecated
|
||||
}
|
||||
|
||||
resource "null_resource" "a" {
|
||||
triggers = "${var.triggers}" # WARNING: Interpolation-only expressions are deprecated
|
||||
|
||||
connection {
|
||||
type = "ssh"
|
||||
host = "${var.triggers["host"]}" # WARNING: Interpolation-only expressions are deprecated
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
single = "${var.triggers["greeting"]}" # WARNING: Interpolation-only expressions are deprecated
|
||||
|
||||
# No warning for this one, because there's more than just one interpolation
|
||||
# in the template.
|
||||
template = " ${var.triggers["greeting"]} "
|
||||
|
||||
wrapped = ["${var.triggers["greeting"]}"] # WARNING: Interpolation-only expressions are deprecated
|
||||
}
|
||||
}
|
||||
|
||||
module "foo" {
|
||||
source = "./foo"
|
||||
foo = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
|
||||
}
|
||||
|
||||
data "null_data_source" "b" {
|
||||
inputs = {
|
||||
host = "${var.triggers["host"]}" # WARNING: Interpolation-only expressions are deprecated
|
||||
}
|
||||
|
||||
has_computed_default = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
|
||||
}
|
||||
|
||||
output "output" {
|
||||
value = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
|
||||
}
|
||||
|
||||
locals {
|
||||
foo = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
|
||||
}
|
||||
Loading…
Reference in new issue