command/show (-json): fix panic if a moduleCall has a nil config (#21569)

In the unlikely event that a moduleCall has a nil config - for example,
if a nested module call includes a variable with a typo in an
attribute - continue gracefully.

This is an unusual edge case in the category of "probably should not happen", caused by
#21568
This commit is contained in:
Kristin Laemmert 2019-06-03 13:04:21 -05:00 committed by GitHub
commit e9e718b318
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 0 deletions

View File

@ -238,6 +238,11 @@ func marshalModuleCalls(c *configs.Config, schemas *terraform.Schemas) map[strin
}
func marshalModuleCall(c *configs.Config, mc *configs.ModuleCall, schemas *terraform.Schemas) moduleCall {
// It is possible to have a module call with a nil config.
if c == nil {
return moduleCall{}
}
ret := moduleCall{
Source: mc.SourceAddr,
VersionConstraint: mc.Version.Required.String(),

View File

@ -0,0 +1,3 @@
module "my_module" {
source = "./modules"
}

View File

@ -0,0 +1,3 @@
module "more" {
source = "./more-modules"
}

View File

@ -0,0 +1,4 @@
variable "misspelled" {
default = "ehllo"
descriptoni = "I am a misspelled attribute"
}

View File

@ -0,0 +1,23 @@
{
"format_version": "0.1",
"terraform_version": "0.12.1-dev",
"planned_values": {
"root_module": {}
},
"configuration": {
"root_module": {
"module_calls": {
"my_module": {
"source": "./modules",
"module": {
"module_calls": {
"more": {
"module": {}
}
}
}
}
}
}
}
}