Skip to content

Instantly share code, notes, and snippets.

@so0k
Created June 15, 2017 02:40
Show Gist options
  • Save so0k/256cde434cbb0b58702249b31203a357 to your computer and use it in GitHub Desktop.
Save so0k/256cde434cbb0b58702249b31203a357 to your computer and use it in GitHub Desktop.
Print Helm's Values.yaml
import yaml
print_format="| {parameter:<40}| | {default:<50}|"
def walk_dict(d,keys=[],depth=0):
for k,v in sorted(d.items(),key=lambda x: x[0]):
keys.append(k)
if isinstance(v,dict):
walk_dict(v,keys,depth+1)
else:
print(print_format.format(parameter='`{0}`'.format(".".join(keys)),default='`{0}`'.format(v)))
keys.pop()
s = open("./values.yaml")
d = yaml.load(s)
walk_dict(d)
@so0k
Copy link
Author

so0k commented Oct 6, 2017

Sample variables.tf

variable "test" {
  description = "Config map"
  default = {
    foo = "bar"
    baz = "qux"
  }
}

Result:

|           Name            |       Default        |                                  Description                                   |Required|
|:--------------------------|:---------------------|:-------------------------------------------------------------------------------|:-------|
|`test.foo                 `|`bar                 `|Config map foo                                                                  |No      |
|`test.baz                 `|`qux                 `|Config map baz                                                                  |No      |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment