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

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 commit is contained in:
Kristin Laemmert 2019-06-03 11:19:03 -04:00
parent ab9e98da3c
commit 703f024cbd
5 changed files with 39 additions and 0 deletions

View File

@ -238,6 +238,12 @@ func marshalModuleCalls(c *configs.Config, schemas *terraform.Schemas) map[strin
}
func marshalModuleCall(c *configs.Config, mc *configs.ModuleCall, schemas *terraform.Schemas) moduleCall {
// It's possible, though unlikely, to have a module call with a nil config
// https://github.com/hashicorp/terraform/issues/21543
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": {}
}
}
}
}
}
}
}
}