Skip to content

Introduce variable validation output into markdown table output. #675

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

rquadling
Copy link

Description of your changes

Work in progress fix for #674.

This currently makes output like

## Inputs

| Name | Description | Type | Default | Required | Validation |
|------|-------------|------|---------|:--------:|------------|
| <a name="input_variable_with_no_validation"></a> [variable\_with\_no\_validation](#input\_variable\_with\_no\_validation) | This variable has no validation | `string` | `""` | no | None |
| <a name="input_variable_with_one_validation"></a> [variable\_with\_one\_validation](#input\_variable\_with\_one\_validation) | This variable has one validation | `string` | `""` | no | var.variable\_with\_one\_validation must be empty or 10 characters long. |
| <a name="input_variable_with_two_validations"></a> [variable\_with\_two\_validations](#input\_variable\_with\_two\_validations) | This variable has two validations | `string` | n/a | yes | var.variable\_with\_two\_validations must be 10 characters long.<br>var.variable\_with\_two\_validations must start with 'magic'. |

which renders as ...

=========================================

Inputs

Name Description Type Default Required Validation
variable_with_no_validation This variable has no validation string "" no None
variable_with_one_validation This variable has one validation string "" no var.variable_with_one_validation must be empty or 10 characters long.
variable_with_two_validations This variable has two validations string n/a yes var.variable_with_two_validations must be 10 characters long.
var.variable_with_two_validations must start with 'magic'.

=========================================

If anyone can provide pointers on what I need to do next (where/how tests are put together, what else to update, etc).

go.sum Outdated
Comment on lines 413 to 1649
github.com/rquadling/terraform-config-inspect v0.0.0-20230303172622-9dd357c8a974 h1:iUSNgwjav+yZfRPSGUyywed1cvQdJPw8HaDRR1TMfw0=
github.com/rquadling/terraform-config-inspect v0.0.0-20230303172622-9dd357c8a974/go.mod h1:l8HcFPm9cQh6Q0KSWoYPiePqMvRFenybP1CH2MjKdlg=
Copy link

Choose a reason for hiding this comment

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

this comment posted yesterday for the upstream terraform-config-inspect libraries support on validation, doesn't look promising

hashicorp/terraform-config-inspect#74 (comment)

would it make sense to use a fork?

Copy link
Author

Choose a reason for hiding this comment

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

I'd be happy to maintain a fork, but I'm not an expert in Terraform or Go, but with help I'm happy to learn.

Copy link
Author

Choose a reason for hiding this comment

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

I've asked if there is any other option of having enhancements being maintained as a community fork or branch.

For me, the biggest issue is about trust. I COULD create the lib, but my experience in Go is not good enough to know if I've introduced something that will cause problems upstream. Having the package within the Hashicorp domain would, I hope, get a greater number of eyes on it and so better reviews, etc.

Another option is to resurrect https://github.com/terraform-docs/terraform-config-inspect.

@@ -12,10 +12,12 @@
{{- if .Config.Settings.Type }} Type |{{ end }}
{{- if .Config.Settings.Default }} Default |{{ end }}
{{- if .Config.Settings.Required }} Required |{{ end }}
{{- if .Config.Settings.Required }} Validation |{{ end }}

Choose a reason for hiding this comment

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

Shouldn't this be Config.Settings.Validation?

@rafaljanicki
Copy link

Hey, that'd be really fancy to have! Any chance to get this merged?

@rquadling
Copy link
Author

The main problem is that the changes to terraform-docs also requires a change to another Hashicorp library that they will NOT accept PRs on. So I cloned it. And made the changes. But GoLang is not my primary language and so I'm needing community support on the fork (make sure I've set it up properly and keeping it upto date, but also working out the "releases" thing as ... again ... GoLang is really not my primary language).

Once the fork of the blocked Hashicorp library is accepted (it could be moved and re-instate the Terraform Docs fork that got abandoned a long time ago), then this PR makes more sense.

For me, the BIG advantage is that, for me, 'validation/error messages' become part of the auto-generated documentation.

It means any module a developer builds, that has validation, they automatically show the possible errors to their users.

It means you really only have to write the documentation about validations once. In code. Where it will be used. No need to manually update a manual or another README.

This really does make a lot of sense.

I just don't know how to shout about it loud enough to get help in getting in it, nor do I know what I've missed that is more "project" oriented.

So anyone reading this comment and has SOME time to spare, please review and help me move it forward!

I know that there are currently conflicts, but this is on 2 files I really don't know how to handle, as like I said, in GoLang, I'm a newbie! So please help!!

rquadling added 14 commits April 9, 2025 17:04
Signed-off-by: Richard Quadling <RQuadling@GMail.com>
Signed-off-by: Richard Quadling <RQuadling@GMail.com>
…from rquadling/terraform-config-inspet

Signed-off-by: Richard Quadling <RQuadling@GMail.com>
These formats already have content filtering, so adding filtering for
validations seemed appropriate

Signed-off-by: Richard Quadling <RQuadling@GMail.com>
Signed-off-by: Richard Quadling <RQuadling@GMail.com>
Signed-off-by: Richard Quadling <RQuadling@GMail.com>
Signed-off-by: Richard Quadling <RQuadling@GMail.com>
Signed-off-by: Richard Quadling <RQuadling@GMail.com>
The tests already had a PrintDescriptions, so added PrintValidations, and
PrintEverything

Signed-off-by: Richard Quadling <RQuadling@GMail.com>
Whilst the variable_with_no_validation is just a standard string, it
made sense to have one just for the set of 0, 1, and many validations.

Signed-off-by: Richard Quadling <RQuadling@GMail.com>
Signed-off-by: Richard Quadling <RQuadling@GMail.com>
The updates here were generated by `make docs`.

Signed-off-by: Richard Quadling <RQuadling@GMail.com>
This was all done by hand as I didn't work out how to automate the
updates and have version control check for things being wrong or
inconsistent.

Signed-off-by: Richard Quadling <RQuadling@GMail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants