Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error if terraform output contains null. #748

Open
goruha opened this issue Jan 26, 2024 · 0 comments · May be fixed by #749
Open

panic: runtime error if terraform output contains null. #748

goruha opened this issue Jan 26, 2024 · 0 comments · May be fixed by #749
Labels

Comments

@goruha
Copy link

goruha commented Jan 26, 2024

Steps to reproduce

  1. Create an empty dir with terraform file example.tf
output "foo" {
  value = "foo"
}

output "bar" {
  value = null
}
  1. Run
terraform plan
terraform apply
terraform output --json > output.json
  1. Run
terraform-docs markdown ./ --output-values --output-values-from ./output.json

Expected

  • Successfully generated markdown

Exists

  • Error
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x93e475]

goroutine 1 [running]:
github.com/terraform-docs/terraform-docs/terraform.loadOutputs(0xc000165b80, 0xc000002180)
	/home/runner/work/terraform-docs/terraform-docs/terraform/load.go:298 +0x2d5
github.com/terraform-docs/terraform-docs/terraform.loadModuleItems(0x7ffdd7128646?, 0xc0000022a8?)
	/home/runner/work/terraform-docs/terraform-docs/terraform/load.go:70 +0x106
github.com/terraform-docs/terraform-docs/terraform.LoadWithOptions(0xc000002180)
	/home/runner/work/terraform-docs/terraform-docs/terraform/load.go:41 +0x38
github.com/terraform-docs/terraform-docs/internal/cli.generateContent(0xc000002180)
	/home/runner/work/terraform-docs/terraform-docs/internal/cli/run.go:326 +0x1c
github.com/terraform-docs/terraform-docs/internal/cli.(*Runtime).RunEFunc(0xc00023b540, 0x0?, {0x0?, 0x0?, 0x0?})
	/home/runner/work/terraform-docs/terraform-docs/internal/cli/run.go:134 +0x1e5
github.com/spf13/cobra.(*Command).execute(0xc000005200, {0xc00023b800, 0x4, 0x4})
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:983 +0xabc
github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1039
github.com/terraform-docs/terraform-docs/cmd.Execute()
	/home/runner/work/terraform-docs/terraform-docs/cmd/root.go:37 +0x1c
main.main()
	/home/runner/work/terraform-docs/terraform-docs/main.go:20 +0x13

Reason

If the output value is null,, it would be skipped in terraform output.

So output.json file will be

{
  "foo": {
    "sensitive": false,
    "type": "string",
    "value": "foo"
  }
}

Point in code to fix https://github.com/terraform-docs/terraform-docs/blob/master/terraform/load.go#L298

Versions

  • terraform v1.2.2
  • terraform docs v0.17.0 795d369 linux/amd64
@goruha goruha added the bug label Jan 26, 2024
@goruha goruha linked a pull request Jan 26, 2024 that will close this issue
@khos2ow khos2ow linked a pull request Mar 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

1 participant