-
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.
Type check variables between modules (#6185)
These tests demonstrates a problem where the types to a module input are not checked. For example, if a module - inner - defines a variable "should_be_a_map" as a map, or with a default variable of map, we do not fail if the user sets the variable value in the outer module to a string value. This is also a problem in nested modules. The implementation changes add a type checking step into the graph evaluation process to ensure invalid types are not passed.
- Loading branch information
Showing
10 changed files
with
175 additions
and
2 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
13 changes: 13 additions & 0 deletions
13
terraform/test-fixtures/plan-module-wrong-var-type-nested/inner/main.tf
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,13 @@ | ||
variable "inner_in" { | ||
type = "map" | ||
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")}" | ||
} |
3 changes: 3 additions & 0 deletions
3
terraform/test-fixtures/plan-module-wrong-var-type-nested/main.tf
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,3 @@ | ||
module "middle" { | ||
source = "./middle" | ||
} |
19 changes: 19 additions & 0 deletions
19
terraform/test-fixtures/plan-module-wrong-var-type-nested/middle/main.tf
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,19 @@ | ||
variable "middle_in" { | ||
type = "map" | ||
default = { | ||
eu-west-1 = "ami-12345" | ||
eu-west-2 = "ami-67890" | ||
} | ||
} | ||
|
||
module "inner" { | ||
source = "../inner" | ||
|
||
inner_in = "hello" | ||
} | ||
|
||
resource "null_resource" "middle_noop" {} | ||
|
||
output "middle_out" { | ||
value = "${lookup(var.middle_in, "us-west-1")}" | ||
} |
7 changes: 7 additions & 0 deletions
7
terraform/test-fixtures/plan-module-wrong-var-type/inner/main.tf
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,7 @@ | ||
variable "map_in" { | ||
type = "map" | ||
default = { | ||
us-west-1 = "ami-12345" | ||
us-west-2 = "ami-67890" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
terraform/test-fixtures/plan-module-wrong-var-type/main.tf
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,10 @@ | ||
variable "input" { | ||
type = "string" | ||
default = "hello world" | ||
} | ||
|
||
module "test" { | ||
source = "./inner" | ||
|
||
map_in = "${var.input}" | ||
} |
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