Skip to content

Commit

Permalink
Fix panic when calling ParseHCL
Browse files Browse the repository at this point in the history
In function ParseHCL, not all fields of tfconfig.Module is checked,
so panic will happen.

Fix #hashicorp#61
  • Loading branch information
zzxwill committed Apr 18, 2021
1 parent 9a80970 commit edc32ad
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tfconfig/load_hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {
switch block.Type {

case "terraform":

if mod.RequiredCore == nil || mod.RequiredProviders == nil {
break
}
content, _, contentDiags := block.Body.PartialContent(terraformBlockSchema)
diags = append(diags, contentDiags...)

Expand Down Expand Up @@ -104,6 +108,10 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {
}

case "variable":

if mod.Variables == nil {
break
}
content, _, contentDiags := block.Body.PartialContent(variableSchema)
diags = append(diags, contentDiags...)

Expand Down Expand Up @@ -177,6 +185,9 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {

case "output":

if mod.Outputs == nil {
break
}
content, _, contentDiags := block.Body.PartialContent(outputSchema)
diags = append(diags, contentDiags...)

Expand Down Expand Up @@ -204,6 +215,9 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {

case "provider":

if mod.RequiredProviders == nil || mod.ProviderConfigs == nil {
break
}
content, _, contentDiags := block.Body.PartialContent(providerConfigSchema)
diags = append(diags, contentDiags...)

Expand Down Expand Up @@ -239,6 +253,10 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {

case "resource", "data":

if mod.ManagedResources == nil || mod.DataResources == nil {
break
}

content, _, contentDiags := block.Body.PartialContent(resourceSchema)
diags = append(diags, contentDiags...)

Expand Down Expand Up @@ -318,6 +336,10 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {

case "module":

if mod.ModuleCalls == nil {
break
}

content, _, contentDiags := block.Body.PartialContent(moduleCallSchema)
diags = append(diags, contentDiags...)

Expand Down

0 comments on commit edc32ad

Please sign in to comment.