-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configs: Warn for deprecated interpolation and quoted type constraints
Following on from de652e2, this introduces deprecation warnings for when an attribute value expression is a template with only a single interpolation sequence, and for variable type constraints given in quotes. As with the previous commit, we allowed these deprecated forms with no warning for a few releases after v0.12.0 to ensure that folks who need to write cross-compatible modules for a while during upgrading would be able to do so, but we're now marking these as explicitly deprecated to guide users towards the new idiomatic forms. The "terraform 0.12upgrade" tool would've already updated configurations to not hit these warnings for those who had pre-existing configurations written for Terraform 0.11. The main target audience for these warnings are newcomers to Terraform who are learning from existing examples already published in various spots on the wider internet that may be showing older Terraform syntax, since those folks will not be running their configurations through the upgrade tool. These warnings will hopefully guide them towards modern Terraform usage during their initial experimentation, and thus reduce the chances of inadvertently adopting the less-readable legacy usage patterns in greenfield projects.
- Loading branch information
1 parent
73d5749
commit 43a1946
Showing
8 changed files
with
152 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"//": "The purpose of this test file is to show that we can use template syntax unwrapping to provide complex expressions without generating the deprecation warnings we'd expect for native syntax.", | ||
"resource": { | ||
"null_resource": { | ||
"baz": { | ||
"//": "This particular use of template syntax is redundant, but we permit it because this is the documented way to use more complex expressions in JSON.", | ||
"triggers": "${ {} }" | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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"]} " | ||
|
||
# No warning for this one, because it's embedded inside a more complex | ||
# expression and our check is only for direct assignment to attributes. | ||
wrapped = ["${var.triggers["greeting"]}"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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 | ||
} |