Merge pull request #27852 from hashicorp/pselle/quoted-keywords

Upgrade to quoted keywords to error
This commit is contained in:
Pam Selle 2021-02-22 08:59:19 -05:00 committed by GitHub
commit 3bd35b2a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 95 additions and 95 deletions

View File

@ -1,4 +1,4 @@
variable "var_without_default" {
type = "string"
type = string
}

View File

@ -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(),
}}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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}"
mod_count_child = var.mod_count_root
}

View File

@ -1,9 +1,9 @@
variable "amis" {
type = "map"
type = map(string)
}
resource "null_resource" "noop" {}
output "amis_out" {
value = "${var.amis}"
value = var.amis
}

View File

@ -1,5 +1,5 @@
variable "amis_in" {
type = "map"
type = map(string)
default = {
"us-west-1" = "ami-123456"
"us-west-2" = "ami-456789"
@ -11,9 +11,9 @@ variable "amis_in" {
module "test" {
source = "./amodule"
amis = "${var.amis_in}"
amis = var.amis_in
}
output "amis_from_module" {
value = "${module.test.amis_out}"
value = module.test.amis_out
}

View File

@ -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" {

View File

@ -1,7 +1,7 @@
variable "list" {
type = "list"
type = list(string)
}
resource "aws_instance" "bar" {
count = "${var.list[0]}"
count = var.list[0]
}

View File

@ -1,5 +1,5 @@
variable "test" {
type = "map"
type = map(string)
default = {
"test" = "1"
}

View File

@ -1,9 +1,9 @@
variable "im_a_string" {
type = "string"
type = string
}
variable "service_region_ami" {
type = "map"
type = map(string)
default = {
us-east-1 = "ami-e4c9db8e"
}

View File

@ -5,5 +5,5 @@ module "mod1" {
module "mod2" {
source = "./mod"
param = ["${module.mod1.out_from_splat[0]}"]
param = [module.mod1.out_from_splat[0]]
}

View File

@ -1,5 +1,5 @@
variable "param" {
type = "list"
type = list(string)
}
resource "aws_instance" "test" {
@ -8,5 +8,5 @@ resource "aws_instance" "test" {
}
output "out_from_splat" {
value = ["${aws_instance.test.*.thing}"]
value = aws_instance.test.*.thing
}

View File

@ -1,5 +1,5 @@
variable "inner_in" {
type = "map"
type = map(string)
default = {
us-west-1 = "ami-12345"
us-west-2 = "ami-67890"
@ -9,5 +9,5 @@ variable "inner_in" {
resource "null_resource" "inner_noop" {}
output "inner_out" {
value = "${lookup(var.inner_in, "us-west-1")}"
value = lookup(var.inner_in, "us-west-1")
}

View File

@ -1,5 +1,5 @@
variable "middle_in" {
type = "map"
type = map(string)
default = {
eu-west-1 = "ami-12345"
eu-west-2 = "ami-67890"
@ -15,5 +15,5 @@ module "inner" {
resource "null_resource" "middle_noop" {}
output "middle_out" {
value = "${lookup(var.middle_in, "us-west-1")}"
value = lookup(var.middle_in, "us-west-1")
}

View File

@ -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
}

View File

@ -1,10 +1,10 @@
variable "input" {
type = "string"
type = string
default = "hello world"
}
module "test" {
source = "./inner"
map_in = "${var.input}"
map_in = var.input
}

View File

@ -1,5 +1,5 @@
variable "maybe_a_map" {
type = "map"
type = map(string)
// No default
}

View File

@ -1,14 +1,14 @@
variable "a" {
default = "foo"
type = "string"
type = string
}
variable "b" {
default = []
type = "list"
type = list(string)
}
variable "c" {
default = {}
type = "map"
type = map(string)
}

View File

@ -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},
},
},
},