Merge pull request #27852 from hashicorp/pselle/quoted-keywords
Upgrade to quoted keywords to error
This commit is contained in:
commit
3bd35b2a18
|
@ -1,4 +1,4 @@
|
|||
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) {
|
||||
if exprIsNativeQuotedString(expr) {
|
||||
// Here we're accepting the pre-0.12 form of variable type argument where
|
||||
// the string values "string", "list" and "map" are accepted has a hint
|
||||
// about the type used primarily for deciding how to parse values
|
||||
// given on the command line and in environment variables.
|
||||
// If a user provides the pre-0.12 form of variable type argument where
|
||||
// the string values "string", "list" and "map" are accepted, we
|
||||
// provide an error to point the user towards using the type system
|
||||
// correctly has a hint.
|
||||
// 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.
|
||||
val, diags := expr.Value(nil)
|
||||
if diags.HasErrors() {
|
||||
|
@ -164,33 +164,33 @@ func decodeVariableType(expr hcl.Expression) (cty.Type, VariableParsingMode, hcl
|
|||
switch str {
|
||||
case "string":
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagWarning,
|
||||
Summary: "Quoted type constraints are deprecated",
|
||||
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\".",
|
||||
Severity: hcl.DiagError,
|
||||
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. Remove the quotes around \"string\".",
|
||||
Subject: expr.Range().Ptr(),
|
||||
})
|
||||
return cty.String, VariableParseLiteral, diags
|
||||
return cty.DynamicPseudoType, VariableParseLiteral, diags
|
||||
case "list":
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagWarning,
|
||||
Summary: "Quoted type constraints are deprecated",
|
||||
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.",
|
||||
Severity: hcl.DiagError,
|
||||
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. Remove the quotes around \"list\" and write list(string) instead to explicitly indicate that the list elements are strings.",
|
||||
Subject: expr.Range().Ptr(),
|
||||
})
|
||||
return cty.List(cty.DynamicPseudoType), VariableParseHCL, diags
|
||||
return cty.DynamicPseudoType, VariableParseHCL, diags
|
||||
case "map":
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagWarning,
|
||||
Summary: "Quoted type constraints are deprecated",
|
||||
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.",
|
||||
Severity: hcl.DiagError,
|
||||
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. Remove the quotes around \"map\" and write map(string) instead to explicitly indicate that the map elements are strings.",
|
||||
Subject: expr.Range().Ptr(),
|
||||
})
|
||||
return cty.Map(cty.DynamicPseudoType), VariableParseHCL, diags
|
||||
return cty.DynamicPseudoType, VariableParseHCL, diags
|
||||
default:
|
||||
return cty.DynamicPseudoType, VariableParseHCL, hcl.Diagnostics{{
|
||||
Severity: hcl.DiagError,
|
||||
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(),
|
||||
}}
|
||||
}
|
||||
|
|
|
@ -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" {
|
||||
type = "string"
|
||||
type = string
|
||||
default = "3"
|
||||
}
|
||||
|
||||
module "child" {
|
||||
source = "./child"
|
||||
mod_count_child = "${var.mod_count_root}"
|
||||
source = "./child"
|
||||
mod_count_child = var.mod_count_root
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
variable "amis" {
|
||||
type = "map"
|
||||
type = map(string)
|
||||
}
|
||||
|
||||
resource "null_resource" "noop" {}
|
||||
|
||||
output "amis_out" {
|
||||
value = "${var.amis}"
|
||||
value = var.amis
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
variable "amis_in" {
|
||||
type = "map"
|
||||
default = {
|
||||
"us-west-1" = "ami-123456"
|
||||
"us-west-2" = "ami-456789"
|
||||
"eu-west-1" = "ami-789012"
|
||||
"eu-west-2" = "ami-989484"
|
||||
}
|
||||
type = map(string)
|
||||
default = {
|
||||
"us-west-1" = "ami-123456"
|
||||
"us-west-2" = "ami-456789"
|
||||
"eu-west-1" = "ami-789012"
|
||||
"eu-west-2" = "ami-989484"
|
||||
}
|
||||
}
|
||||
|
||||
module "test" {
|
||||
source = "./amodule"
|
||||
source = "./amodule"
|
||||
|
||||
amis = "${var.amis_in}"
|
||||
amis = var.amis_in
|
||||
}
|
||||
|
||||
output "amis_from_module" {
|
||||
value = "${module.test.amis_out}"
|
||||
value = module.test.amis_out
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ variable "num" {
|
|||
}
|
||||
|
||||
variable "source_ids" {
|
||||
type = "list"
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "source_names" {
|
||||
type = "list"
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
resource "test_thing" "multi_count_var" {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
variable "list" {
|
||||
type = "list"
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
count = "${var.list[0]}"
|
||||
count = var.list[0]
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
variable "test" {
|
||||
type = "map"
|
||||
type = map(string)
|
||||
default = {
|
||||
"test" = "1"
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
variable "im_a_string" {
|
||||
type = "string"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "service_region_ami" {
|
||||
type = "map"
|
||||
default = {
|
||||
us-east-1 = "ami-e4c9db8e"
|
||||
}
|
||||
type = map(string)
|
||||
default = {
|
||||
us-east-1 = "ami-e4c9db8e"
|
||||
}
|
||||
}
|
||||
|
||||
resource "null_resource" "noop" {}
|
||||
|
|
|
@ -5,5 +5,5 @@ module "mod1" {
|
|||
|
||||
module "mod2" {
|
||||
source = "./mod"
|
||||
param = ["${module.mod1.out_from_splat[0]}"]
|
||||
param = [module.mod1.out_from_splat[0]]
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
variable "param" {
|
||||
type = "list"
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
resource "aws_instance" "test" {
|
||||
count = "2"
|
||||
count = "2"
|
||||
thing = "doesnt"
|
||||
}
|
||||
|
||||
output "out_from_splat" {
|
||||
value = ["${aws_instance.test.*.thing}"]
|
||||
value = aws_instance.test.*.thing
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
variable "inner_in" {
|
||||
type = "map"
|
||||
default = {
|
||||
us-west-1 = "ami-12345"
|
||||
us-west-2 = "ami-67890"
|
||||
}
|
||||
type = map(string)
|
||||
default = {
|
||||
us-west-1 = "ami-12345"
|
||||
us-west-2 = "ami-67890"
|
||||
}
|
||||
}
|
||||
|
||||
resource "null_resource" "inner_noop" {}
|
||||
|
||||
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" {
|
||||
source = "./middle"
|
||||
source = "./middle"
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
variable "middle_in" {
|
||||
type = "map"
|
||||
default = {
|
||||
eu-west-1 = "ami-12345"
|
||||
eu-west-2 = "ami-67890"
|
||||
}
|
||||
type = map(string)
|
||||
default = {
|
||||
eu-west-1 = "ami-12345"
|
||||
eu-west-2 = "ami-67890"
|
||||
}
|
||||
}
|
||||
|
||||
module "inner" {
|
||||
source = "../inner"
|
||||
source = "../inner"
|
||||
|
||||
inner_in = "hello"
|
||||
inner_in = "hello"
|
||||
}
|
||||
|
||||
resource "null_resource" "middle_noop" {}
|
||||
|
||||
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" {
|
||||
type = "map"
|
||||
type = map(string)
|
||||
|
||||
default = {
|
||||
us-west-1 = "ami-12345"
|
||||
|
@ -9,5 +9,5 @@ variable "map_in" {
|
|||
|
||||
// We have to reference it so it isn't pruned
|
||||
output "output" {
|
||||
value = "${var.map_in}"
|
||||
value = var.map_in
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
variable "input" {
|
||||
type = "string"
|
||||
default = "hello world"
|
||||
type = string
|
||||
default = "hello world"
|
||||
}
|
||||
|
||||
module "test" {
|
||||
source = "./inner"
|
||||
source = "./inner"
|
||||
|
||||
map_in = "${var.input}"
|
||||
map_in = var.input
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
variable "maybe_a_map" {
|
||||
type = "map"
|
||||
type = map(string)
|
||||
|
||||
// No default
|
||||
// No default
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
variable "a" {
|
||||
default = "foo"
|
||||
type = "string"
|
||||
default = "foo"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "b" {
|
||||
default = []
|
||||
type = "list"
|
||||
default = []
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "c" {
|
||||
default = {}
|
||||
type = "map"
|
||||
default = {}
|
||||
type = map(string)
|
||||
}
|
||||
|
|
|
@ -30,21 +30,21 @@ func TestVariables(t *testing.T) {
|
|||
},
|
||||
},
|
||||
"b": &InputValue{
|
||||
Value: cty.ListValEmpty(cty.DynamicPseudoType),
|
||||
Value: cty.ListValEmpty(cty.String),
|
||||
SourceType: ValueFromConfig,
|
||||
SourceRange: tfdiags.SourceRange{
|
||||
Filename: "testdata/vars-basic/main.tf",
|
||||
Start: tfdiags.SourcePos{Line: 6, Column: 1, Byte: 58},
|
||||
End: tfdiags.SourcePos{Line: 6, Column: 13, Byte: 70},
|
||||
Start: tfdiags.SourcePos{Line: 6, Column: 1, Byte: 55},
|
||||
End: tfdiags.SourcePos{Line: 6, Column: 13, Byte: 67},
|
||||
},
|
||||
},
|
||||
"c": &InputValue{
|
||||
Value: cty.MapValEmpty(cty.DynamicPseudoType),
|
||||
Value: cty.MapValEmpty(cty.String),
|
||||
SourceType: ValueFromConfig,
|
||||
SourceRange: tfdiags.SourceRange{
|
||||
Filename: "testdata/vars-basic/main.tf",
|
||||
Start: tfdiags.SourcePos{Line: 11, Column: 1, Byte: 111},
|
||||
End: tfdiags.SourcePos{Line: 11, Column: 13, Byte: 123},
|
||||
Start: tfdiags.SourcePos{Line: 11, Column: 1, Byte: 113},
|
||||
End: tfdiags.SourcePos{Line: 11, Column: 13, Byte: 125},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue