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

Fix output values with null #749

Merged
merged 1 commit into from
May 27, 2024

Conversation

goruha
Copy link
Contributor

@goruha 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/cobra@v1.8.0/command.go:983 +0xabc
github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
	/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.0/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

Reference

#748

@goruha
Copy link
Contributor Author

goruha commented Jan 27, 2024

@khos2ow @metmajer may I have a review pls

@khos2ow khos2ow linked an issue Mar 20, 2024 that may be closed by this pull request
@khos2ow
Copy link
Member

khos2ow commented Mar 23, 2024

@goruha thank you for the PR and your patience. Can you please rebase your PR?

Signed-off-by: Igor Rodionov <goruha@gmail.com>
@goruha goruha reopened this Mar 25, 2024
@goruha
Copy link
Contributor Author

goruha commented Mar 25, 2024

@khos2ow done

@goruha
Copy link
Contributor Author

goruha commented Apr 4, 2024

@khos2ow friendly notify about this PR.
Thanks

@goruha
Copy link
Contributor Author

goruha commented Apr 8, 2024

@khos2ow tests passed.
How about to get this merged?

@goruha
Copy link
Contributor Author

goruha commented May 13, 2024

@khos2ow can we get the PR merged?

Copy link
Member

@khos2ow khos2ow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @goruha and sorry for the long delay!

@khos2ow khos2ow merged commit 80c406f into terraform-docs:master May 27, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

panic: runtime error if terraform output contains null.
3 participants