Replies: 1 comment
-
In a very super general sense, yes. The output you see is actually a template. You can supply your own templates. That's the easy answer. The harder one is where would you now get the new default value from. So, my variables: variable "empty_list" {
description = "The empty list"
type = list(string)
default = []
}
variable "empty_set" {
description = "The empty set"
type = set(string)
default = []
} This is the template I've gotten working within the content: |-
{{- if .Config.Sections.Inputs -}}
{{- if not .Module.Inputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Inputs
No inputs.
{{- end }}
{{ else }}
{{- indent 0 "#" }} Inputs
| Name | Description |
{{- if .Config.Settings.Type }} Type |{{ end }}
{{- if .Config.Settings.Default }} Default |{{ end }}
{{- if .Config.Settings.Required }} Required |{{ end }}
|------|-------------|
{{- if .Config.Settings.Type }}------|{{ end }}
{{- if .Config.Settings.Default }}---------|{{ end }}
{{- if .Config.Settings.Required }}:--------:|{{ end }}
{{- range .Module.Inputs }}
| {{ anchorNameMarkdown "input" .Name }} | {{ tostring .Description | sanitizeMarkdownTbl }} |
{{- if $.Config.Settings.Type -}}
{{ printf " " }}{{ tostring .Type | sanitizeMarkdownTbl }} |
{{- end -}}
{{- if $.Config.Settings.Default -}}
{{ printf " " }}
{{- if eq (.GetValue | sanitizeMarkdownTbl) "[]" -}}
{{- if hasPrefix "list" (tostring .Type | sanitizeMarkdownTbl) -}}
empty list
{{- else if hasPrefix "set" (tostring .Type | sanitizeMarkdownTbl) -}}
empty set
{{- else -}}
{{ .GetValue | sanitizeMarkdownTbl }}
{{- end -}}
{{- else -}}
{{ .GetValue | sanitizeMarkdownTbl }}
{{- end }} |
{{- end -}}
{{- if $.Config.Settings.Required -}}
{{ printf " " }}{{ ternary .Required "yes" "no" }} |
{{- end -}}
{{- end }}
{{ end }}
{{ end -}} And the output: ## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_empty_list"></a> [empty\_list](#input\_empty\_list) | The empty list | list(string) | empty list | no |
| <a name="input_empty_set"></a> [empty\_set](#input\_empty\_set) | The empty set | set(string) | empty set | no | The orginal template for the default value was: {{- if $.Config.Settings.Default -}}
{{ printf " " }}{{ .GetValue | sanitizeMarkdownTbl }} |
{{- end -}} To get the entire document, with just the Inputs replaced, ... I've not seen a way other than pulling in the entire template. Which is here! content: |-
{{- if .Config.Sections.Header -}}
{{- with .Module.Header -}}
{{ sanitizeSection . }}
{{ printf "\n" }}
{{- end -}}
{{ end -}}
{{- if .Config.Sections.Requirements -}}
{{- if not .Module.Requirements -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Requirements
No requirements.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Requirements
| Name | Version |
|------|---------|
{{- range .Module.Requirements }}
| {{ anchorNameMarkdown "requirement" .Name }} | {{ tostring .Version | default "n/a" }} |
{{- end }}
{{ end }}
{{ end -}}
{{- if .Config.Sections.Providers -}}
{{- if not .Module.Providers -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Providers
No providers.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Providers
| Name | Version |
|------|---------|
{{- range .Module.Providers }}
| {{ anchorNameMarkdown "provider" .FullName }} | {{ tostring .Version | default "n/a" }} |
{{- end }}
{{ end }}
{{ end -}}
{{- if .Config.Sections.ModuleCalls -}}
{{- if not .Module.ModuleCalls -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Modules
No modules.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Modules
| Name | Source | Version |
|------|--------|---------|
{{- range .Module.ModuleCalls }}
| {{ anchorNameMarkdown "module" .Name }} | {{ .Source }} | {{ .Version | default "n/a" }} |
{{- end }}
{{ end }}
{{ end -}}
{{- if or .Config.Sections.Resources .Config.Sections.DataSources -}}
{{- if not .Module.Resources -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Resources
No resources.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Resources
| Name | Type |
|------|------|
{{- range .Module.Resources }}
{{- $isResource := and $.Config.Sections.Resources ( eq "resource" (printf "%s" .GetMode)) }}
{{- $isDataResource := and $.Config.Sections.DataSources ( eq "data source" (printf "%s" .GetMode)) }}
{{- if or $isResource $isDataResource }}
{{- $fullspec := ternary .URL (printf "[%s](%s)" .Spec .URL) .Spec }}
| {{ $fullspec }} | {{ .GetMode }} |
{{- end }}
{{- end }}
{{ end }}
{{ end -}}
{{- if .Config.Sections.Inputs -}}
{{- if not .Module.Inputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Inputs
No inputs.
{{- end }}
{{ else }}
{{- indent 0 "#" }} Inputs
| Name | Description |
{{- if .Config.Settings.Type }} Type |{{ end }}
{{- if .Config.Settings.Default }} Default |{{ end }}
{{- if .Config.Settings.Required }} Required |{{ end }}
|------|-------------|
{{- if .Config.Settings.Type }}------|{{ end }}
{{- if .Config.Settings.Default }}---------|{{ end }}
{{- if .Config.Settings.Required }}:--------:|{{ end }}
{{- range .Module.Inputs }}
| {{ anchorNameMarkdown "input" .Name }} | {{ tostring .Description | sanitizeMarkdownTbl }} |
{{- if $.Config.Settings.Type -}}
{{ printf " " }}{{ tostring .Type | sanitizeMarkdownTbl }} |
{{- end -}}
{{- if $.Config.Settings.Default -}}
{{ printf " " }}
{{- if eq (.GetValue | sanitizeMarkdownTbl) "[]" -}}
{{- if hasPrefix "list" (tostring .Type | sanitizeMarkdownTbl) -}}
empty list
{{- else if hasPrefix "set" (tostring .Type | sanitizeMarkdownTbl) -}}
empty set
{{- else -}}
{{ .GetValue | sanitizeMarkdownTbl }}
{{- end -}}
{{- else -}}
{{ .GetValue | sanitizeMarkdownTbl }}
{{- end }} |
{{- end -}}
{{- if $.Config.Settings.Required -}}
{{ printf " " }}{{ ternary .Required "yes" "no" }} |
{{- end -}}
{{- end }}
{{ end }}
{{ end -}}
{{- if .Config.Sections.Outputs -}}
{{- if not .Module.Outputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Outputs
No outputs.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Outputs
| Name | Description |{{ if .Config.OutputValues.Enabled }} Value |{{ if $.Config.Settings.Sensitive }} Sensitive |{{ end }}{{ end }}
|------|-------------|{{ if .Config.OutputValues.Enabled }}-------|{{ if $.Config.Settings.Sensitive }}:---------:|{{ end }}{{ end }}
{{- range .Module.Outputs }}
| {{ anchorNameMarkdown "output" .Name }} | {{ tostring .Description | sanitizeMarkdownTbl }} |
{{- if $.Config.OutputValues.Enabled -}}
{{- $sensitive := ternary .Sensitive "<sensitive>" .GetValue -}}
{{ printf " " }}{{ $sensitive | sanitizeMarkdownTbl }} |
{{- if $.Config.Settings.Sensitive -}}
{{ printf " " }}{{ ternary .Sensitive "yes" "no" }} |
{{- end -}}
{{- end -}}
{{- end }}
{{ end }}
{{ end -}}
{{- if .Config.Sections.Footer -}}
{{- with .Module.Footer -}}
{{ sanitizeSection . }}
{{ printf "\n" }}
{{- end -}}
{{ end -}} which then produces: ## Requirements
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.0 |
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.6 |
## Providers
| Name | Version |
|------|---------|
| <a name="provider_terraform"></a> [terraform](#provider\_terraform) | n/a |
## Modules
| Name | Source | Version |
|------|--------|---------|
| <a name="module_ecs-service"></a> [ecs-service](#module\_ecs-service) | ../terraform-aws-ecs-service | n/a |
| <a name="module_parameter-store"></a> [parameter-store](#module\_parameter-store) | ../terraform-aws-parameter-store | n/a |
## Resources
| Name | Type |
|------|------|
| [terraform_remote_state.old-compute](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_empty_list"></a> [empty\_list](#input\_empty\_list) | The empty list | list(string) | empty list | no |
| <a name="input_empty_set"></a> [empty\_set](#input\_empty\_set) | The empty set | set(string) | empty set | no |
## Outputs
No outputs.
But please note ... I've only been a Go developer for about a month and only ever worked with existing projects and so followed what is, not necessarily better/worse ways. I've made a PR to add input validation outputs via a fork of a Hashicorp library (waiting on terraform-docs approval / merge!). The template MAY be able to be loaded in fragments ... not tried that yet. But hopefully this is proof enough that you can use the original templates and apply a bit of logic/thought/head-scratching and come up with your own solution. |
Beta Was this translation helpful? Give feedback.
-
Hi, is it possible to override what is shown as the default value of a variable in th Inputs table?
Some other tools allow to do this by using comments, for example
This would results in:
Inputs
foo
my variable description
list(string)
empty list
Instead of
Inputs
foo
my variable description
list(string)
[]
Beta Was this translation helpful? Give feedback.
All reactions