Upgrade to quoted keywords to error
The warning about deprecation is upgraded to an error
This commit is contained in:
parent
4e345b6d27
commit
8f7807684a
|
@ -1,4 +1,4 @@
|
||||||
variable "var_without_default" {
|
variable "var_without_default" {
|
||||||
type = "string"
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,12 +149,12 @@ func decodeVariableBlock(block *hcl.Block, override bool) (*Variable, hcl.Diagno
|
||||||
|
|
||||||
func decodeVariableType(expr hcl.Expression) (cty.Type, VariableParsingMode, hcl.Diagnostics) {
|
func decodeVariableType(expr hcl.Expression) (cty.Type, VariableParsingMode, hcl.Diagnostics) {
|
||||||
if exprIsNativeQuotedString(expr) {
|
if exprIsNativeQuotedString(expr) {
|
||||||
// Here we're accepting the pre-0.12 form of variable type argument where
|
// If a user provides the pre-0.12 form of variable type argument where
|
||||||
// the string values "string", "list" and "map" are accepted has a hint
|
// the string values "string", "list" and "map" are accepted, we
|
||||||
// about the type used primarily for deciding how to parse values
|
// provide an error to point the user towards using the type system
|
||||||
// given on the command line and in environment variables.
|
// correctly has a hint.
|
||||||
// Only the native syntax ends up in this codepath; we handle the
|
// Only the native syntax ends up in this codepath; we handle the
|
||||||
// JSON syntax (which is, of course, quoted even in the new format)
|
// JSON syntax (which is, of course, quoted within the type system)
|
||||||
// in the normal codepath below.
|
// in the normal codepath below.
|
||||||
val, diags := expr.Value(nil)
|
val, diags := expr.Value(nil)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
|
@ -164,33 +164,33 @@ func decodeVariableType(expr hcl.Expression) (cty.Type, VariableParsingMode, hcl
|
||||||
switch str {
|
switch str {
|
||||||
case "string":
|
case "string":
|
||||||
diags = append(diags, &hcl.Diagnostic{
|
diags = append(diags, &hcl.Diagnostic{
|
||||||
Severity: hcl.DiagWarning,
|
Severity: hcl.DiagError,
|
||||||
Summary: "Quoted type constraints are deprecated",
|
Summary: "Invalid quoted type constraints",
|
||||||
Detail: "Terraform 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed in a future version of Terraform. To silence this warning, remove the quotes around \"string\".",
|
Detail: "Terraform 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed in a future version of Terraform. Remove the quotes around \"string\".",
|
||||||
Subject: expr.Range().Ptr(),
|
Subject: expr.Range().Ptr(),
|
||||||
})
|
})
|
||||||
return cty.String, VariableParseLiteral, diags
|
return cty.DynamicPseudoType, VariableParseLiteral, diags
|
||||||
case "list":
|
case "list":
|
||||||
diags = append(diags, &hcl.Diagnostic{
|
diags = append(diags, &hcl.Diagnostic{
|
||||||
Severity: hcl.DiagWarning,
|
Severity: hcl.DiagError,
|
||||||
Summary: "Quoted type constraints are deprecated",
|
Summary: "Invalid quoted type constraints",
|
||||||
Detail: "Terraform 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed in a future version of Terraform. To silence this warning, remove the quotes around \"list\" and write list(string) instead to explicitly indicate that the list elements are strings.",
|
Detail: "Terraform 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed in a future version of Terraform. Remove the quotes around \"list\" and write list(string) instead to explicitly indicate that the list elements are strings.",
|
||||||
Subject: expr.Range().Ptr(),
|
Subject: expr.Range().Ptr(),
|
||||||
})
|
})
|
||||||
return cty.List(cty.DynamicPseudoType), VariableParseHCL, diags
|
return cty.DynamicPseudoType, VariableParseHCL, diags
|
||||||
case "map":
|
case "map":
|
||||||
diags = append(diags, &hcl.Diagnostic{
|
diags = append(diags, &hcl.Diagnostic{
|
||||||
Severity: hcl.DiagWarning,
|
Severity: hcl.DiagError,
|
||||||
Summary: "Quoted type constraints are deprecated",
|
Summary: "Invalid quoted type constraints",
|
||||||
Detail: "Terraform 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed in a future version of Terraform. To silence this warning, remove the quotes around \"map\" and write map(string) instead to explicitly indicate that the map elements are strings.",
|
Detail: "Terraform 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed in a future version of Terraform. Remove the quotes around \"map\" and write map(string) instead to explicitly indicate that the map elements are strings.",
|
||||||
Subject: expr.Range().Ptr(),
|
Subject: expr.Range().Ptr(),
|
||||||
})
|
})
|
||||||
return cty.Map(cty.DynamicPseudoType), VariableParseHCL, diags
|
return cty.DynamicPseudoType, VariableParseHCL, diags
|
||||||
default:
|
default:
|
||||||
return cty.DynamicPseudoType, VariableParseHCL, hcl.Diagnostics{{
|
return cty.DynamicPseudoType, VariableParseHCL, hcl.Diagnostics{{
|
||||||
Severity: hcl.DiagError,
|
Severity: hcl.DiagError,
|
||||||
Summary: "Invalid legacy variable type hint",
|
Summary: "Invalid legacy variable type hint",
|
||||||
Detail: `The legacy variable type hint form, using a quoted string, allows only the values "string", "list", and "map". To provide a full type expression, remove the surrounding quotes and give the type expression directly.`,
|
Detail: `To provide a full type expression, remove the surrounding quotes and give the type expression directly.`,
|
||||||
Subject: expr.Range().Ptr(),
|
Subject: expr.Range().Ptr(),
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
variable "bad_string" {
|
||||||
|
type = "string" # ERROR: Invalid quoted type constraints
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bad_map" {
|
||||||
|
type = "map" # ERROR: Invalid quoted type constraints
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bad_list" {
|
||||||
|
type = "list" # ERROR: Invalid quoted type constraints
|
||||||
|
}
|
|
@ -1,11 +0,0 @@
|
||||||
variable "bad_string" {
|
|
||||||
type = "string" # WARNING: Quoted type constraints are deprecated
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "bad_map" {
|
|
||||||
type = "map" # WARNING: Quoted type constraints are deprecated
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "bad_list" {
|
|
||||||
type = "list" # WARNING: Quoted type constraints are deprecated
|
|
||||||
}
|
|
|
@ -1,9 +1,9 @@
|
||||||
variable "mod_count_root" {
|
variable "mod_count_root" {
|
||||||
type = "string"
|
type = string
|
||||||
default = "3"
|
default = "3"
|
||||||
}
|
}
|
||||||
|
|
||||||
module "child" {
|
module "child" {
|
||||||
source = "./child"
|
source = "./child"
|
||||||
mod_count_child = "${var.mod_count_root}"
|
mod_count_child = var.mod_count_root
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
variable "amis" {
|
variable "amis" {
|
||||||
type = "map"
|
type = map(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "null_resource" "noop" {}
|
resource "null_resource" "noop" {}
|
||||||
|
|
||||||
output "amis_out" {
|
output "amis_out" {
|
||||||
value = "${var.amis}"
|
value = var.amis
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
variable "amis_in" {
|
variable "amis_in" {
|
||||||
type = "map"
|
type = map(string)
|
||||||
default = {
|
default = {
|
||||||
"us-west-1" = "ami-123456"
|
"us-west-1" = "ami-123456"
|
||||||
"us-west-2" = "ami-456789"
|
"us-west-2" = "ami-456789"
|
||||||
"eu-west-1" = "ami-789012"
|
"eu-west-1" = "ami-789012"
|
||||||
"eu-west-2" = "ami-989484"
|
"eu-west-2" = "ami-989484"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module "test" {
|
module "test" {
|
||||||
source = "./amodule"
|
source = "./amodule"
|
||||||
|
|
||||||
amis = "${var.amis_in}"
|
amis = var.amis_in
|
||||||
}
|
}
|
||||||
|
|
||||||
output "amis_from_module" {
|
output "amis_from_module" {
|
||||||
value = "${module.test.amis_out}"
|
value = module.test.amis_out
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ variable "num" {
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "source_ids" {
|
variable "source_ids" {
|
||||||
type = "list"
|
type = list(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "source_names" {
|
variable "source_names" {
|
||||||
type = "list"
|
type = list(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "test_thing" "multi_count_var" {
|
resource "test_thing" "multi_count_var" {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
variable "list" {
|
variable "list" {
|
||||||
type = "list"
|
type = list(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
count = "${var.list[0]}"
|
count = var.list[0]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
variable "test" {
|
variable "test" {
|
||||||
type = "map"
|
type = map(string)
|
||||||
default = {
|
default = {
|
||||||
"test" = "1"
|
"test" = "1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
variable "im_a_string" {
|
variable "im_a_string" {
|
||||||
type = "string"
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "service_region_ami" {
|
variable "service_region_ami" {
|
||||||
type = "map"
|
type = map(string)
|
||||||
default = {
|
default = {
|
||||||
us-east-1 = "ami-e4c9db8e"
|
us-east-1 = "ami-e4c9db8e"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "null_resource" "noop" {}
|
resource "null_resource" "noop" {}
|
||||||
|
|
|
@ -5,5 +5,5 @@ module "mod1" {
|
||||||
|
|
||||||
module "mod2" {
|
module "mod2" {
|
||||||
source = "./mod"
|
source = "./mod"
|
||||||
param = ["${module.mod1.out_from_splat[0]}"]
|
param = [module.mod1.out_from_splat[0]]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
variable "param" {
|
variable "param" {
|
||||||
type = "list"
|
type = list(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "test" {
|
resource "aws_instance" "test" {
|
||||||
count = "2"
|
count = "2"
|
||||||
thing = "doesnt"
|
thing = "doesnt"
|
||||||
}
|
}
|
||||||
|
|
||||||
output "out_from_splat" {
|
output "out_from_splat" {
|
||||||
value = ["${aws_instance.test.*.thing}"]
|
value = aws_instance.test.*.thing
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
variable "inner_in" {
|
variable "inner_in" {
|
||||||
type = "map"
|
type = map(string)
|
||||||
default = {
|
default = {
|
||||||
us-west-1 = "ami-12345"
|
us-west-1 = "ami-12345"
|
||||||
us-west-2 = "ami-67890"
|
us-west-2 = "ami-67890"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "null_resource" "inner_noop" {}
|
resource "null_resource" "inner_noop" {}
|
||||||
|
|
||||||
output "inner_out" {
|
output "inner_out" {
|
||||||
value = "${lookup(var.inner_in, "us-west-1")}"
|
value = lookup(var.inner_in, "us-west-1")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module "middle" {
|
module "middle" {
|
||||||
source = "./middle"
|
source = "./middle"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
variable "middle_in" {
|
variable "middle_in" {
|
||||||
type = "map"
|
type = map(string)
|
||||||
default = {
|
default = {
|
||||||
eu-west-1 = "ami-12345"
|
eu-west-1 = "ami-12345"
|
||||||
eu-west-2 = "ami-67890"
|
eu-west-2 = "ami-67890"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module "inner" {
|
module "inner" {
|
||||||
source = "../inner"
|
source = "../inner"
|
||||||
|
|
||||||
inner_in = "hello"
|
inner_in = "hello"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "null_resource" "middle_noop" {}
|
resource "null_resource" "middle_noop" {}
|
||||||
|
|
||||||
output "middle_out" {
|
output "middle_out" {
|
||||||
value = "${lookup(var.middle_in, "us-west-1")}"
|
value = lookup(var.middle_in, "us-west-1")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
variable "map_in" {
|
variable "map_in" {
|
||||||
type = "map"
|
type = map(string)
|
||||||
|
|
||||||
default = {
|
default = {
|
||||||
us-west-1 = "ami-12345"
|
us-west-1 = "ami-12345"
|
||||||
|
@ -9,5 +9,5 @@ variable "map_in" {
|
||||||
|
|
||||||
// We have to reference it so it isn't pruned
|
// We have to reference it so it isn't pruned
|
||||||
output "output" {
|
output "output" {
|
||||||
value = "${var.map_in}"
|
value = var.map_in
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
variable "input" {
|
variable "input" {
|
||||||
type = "string"
|
type = string
|
||||||
default = "hello world"
|
default = "hello world"
|
||||||
}
|
}
|
||||||
|
|
||||||
module "test" {
|
module "test" {
|
||||||
source = "./inner"
|
source = "./inner"
|
||||||
|
|
||||||
map_in = "${var.input}"
|
map_in = var.input
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
variable "maybe_a_map" {
|
variable "maybe_a_map" {
|
||||||
type = "map"
|
type = map(string)
|
||||||
|
|
||||||
// No default
|
// No default
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
variable "a" {
|
variable "a" {
|
||||||
default = "foo"
|
default = "foo"
|
||||||
type = "string"
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "b" {
|
variable "b" {
|
||||||
default = []
|
default = []
|
||||||
type = "list"
|
type = list(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "c" {
|
variable "c" {
|
||||||
default = {}
|
default = {}
|
||||||
type = "map"
|
type = map(string)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,21 +30,21 @@ func TestVariables(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"b": &InputValue{
|
"b": &InputValue{
|
||||||
Value: cty.ListValEmpty(cty.DynamicPseudoType),
|
Value: cty.ListValEmpty(cty.String),
|
||||||
SourceType: ValueFromConfig,
|
SourceType: ValueFromConfig,
|
||||||
SourceRange: tfdiags.SourceRange{
|
SourceRange: tfdiags.SourceRange{
|
||||||
Filename: "testdata/vars-basic/main.tf",
|
Filename: "testdata/vars-basic/main.tf",
|
||||||
Start: tfdiags.SourcePos{Line: 6, Column: 1, Byte: 58},
|
Start: tfdiags.SourcePos{Line: 6, Column: 1, Byte: 55},
|
||||||
End: tfdiags.SourcePos{Line: 6, Column: 13, Byte: 70},
|
End: tfdiags.SourcePos{Line: 6, Column: 13, Byte: 67},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"c": &InputValue{
|
"c": &InputValue{
|
||||||
Value: cty.MapValEmpty(cty.DynamicPseudoType),
|
Value: cty.MapValEmpty(cty.String),
|
||||||
SourceType: ValueFromConfig,
|
SourceType: ValueFromConfig,
|
||||||
SourceRange: tfdiags.SourceRange{
|
SourceRange: tfdiags.SourceRange{
|
||||||
Filename: "testdata/vars-basic/main.tf",
|
Filename: "testdata/vars-basic/main.tf",
|
||||||
Start: tfdiags.SourcePos{Line: 11, Column: 1, Byte: 111},
|
Start: tfdiags.SourcePos{Line: 11, Column: 1, Byte: 113},
|
||||||
End: tfdiags.SourcePos{Line: 11, Column: 13, Byte: 123},
|
End: tfdiags.SourcePos{Line: 11, Column: 13, Byte: 125},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue