Skip to content

Extract and render output values from Terraform #191

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

Merged
merged 25 commits into from
Feb 19, 2020
Merged

Extract and render output values from Terraform #191

merged 25 commits into from
Feb 19, 2020

Conversation

gshel
Copy link
Contributor

@gshel gshel commented Feb 6, 2020

Prerequisites

Put an x into the box(es) that apply:

  • This pull request fixes a bug.
  • This pull request adds a feature.
  • This pull request enhances existing functionality.
  • This pull request introduces breaking change.

For more information, see the Contributing Guide.

Description

This PR allows users to pass the global flag '--output-values PATH' to inject a project's outputs' values into the chosen format.

  1. cd intoYourTF/project
  2. terraform outputs --json > output_values.json
  3. terraform-docs markdown table --output-values output_values.json

Issues Resolved

#165

Checklist

Put an x into all boxes that apply:

Tests

  • I have added tests to cover my changes.
  • All tests pass when I run make test.

Documentation

  • My change requires a change to the documentation.
  • [TBD] I have updated the documentation accordingly.

Code Style

  • My code follows the code style of this project.

Pass empty string to CreateModule.outputValuePath
@gshel gshel marked this pull request as ready for review February 6, 2020 20:03
@gshel gshel requested a review from khos2ow February 6, 2020 20:03
@gshel
Copy link
Contributor Author

gshel commented Feb 6, 2020

Some things I can think off of the top of my head that I would like to hear your input on:

  • If an output value is "" should that display as n/a?

  • If an output value is "" should json/yaml omit the empty field?

  • I looked over the documentation, noticing that there are not currently sections detailing flags. Since you marked my issue with the documentation label, I wanted to confirm that you'd like it added into the readme.

  • I have some clunky if/else statements that I'm wondering if there are alternative, elegant solutions for (e.g. internal/pkg/tfconf/module.go:142)

As for tests, I was hoping to get your feedback on the code first and then I will tackle those.

I appreciate your feedback; apologies in advance for n00b go questions :)

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.

That's awesome @gshel, thank you so much. I have some comments and suggestions bellow, please feel free to reach out before you start refactoring/applying changes, if you have any questions, suggestions or objections.

@khos2ow
Copy link
Member

khos2ow commented Feb 8, 2020

  • If an output value is "" should that display as n/a?
  • If an output value is "" should json/yaml omit the empty field?

We definitely should not drop the empty field, I don't have an answer for it at the moment, check out #191 (comment)

  • I looked over the documentation, noticing that there are not currently sections detailing flags. Since you marked my issue with the documentation label, I wanted to confirm that you'd like it added into the readme.

There are some documentation available here. I'm currently working on an enhancement to auto-generate that from whatever exists in cmd/. I put the documentation label to not forget about it.

  • I have some clunky if/else statements that I'm wondering if there are alternative, elegant solutions for (e.g. internal/pkg/tfconf/module.go:142)

That's true :) we need to address that after/with this #191 (comment)

@khos2ow khos2ow linked an issue Feb 10, 2020 that may be closed by this pull request
2 tasks
iMartyn and others added 6 commits February 13, 2020 10:54
Co-authored-by: Khosrow Moossavi <khos2ow@gmail.com>
* Auto generate formats document from examples

* fix lint issues
Read the outputValuesPath from an env variable

Use an env var with a path for '--output-values'

Update Changelog

Use an env var with a path for '--output-values'

Update Changelog

properly write output values for evrythng but yaml
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 @gshel for the hard work, this PR's starting to get shape! I have some comments below.

@gshel
Copy link
Contributor Author

gshel commented Feb 15, 2020

I'm not sure how we can test --outputValues without including the path to my pre-generated output_values.json. I ran into issues running terraform output --json inside the examples folder because I'm using Terraform v0.12.19. Ideas?

@khos2ow khos2ow changed the title WIP: #165 Allow users to pass '--output-values' Extract and render output values from Terraform Feb 17, 2020
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.

Almost finished, we're getting there! I have some small comments.

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 so much @gshel for the brilliant work ❤️

@khos2ow khos2ow merged commit 31cdef0 into terraform-docs:master Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inject terraform output into terraform-docs as an additional 'Value' field
3 participants