Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jerowe committed Apr 25, 2022
1 parent c8c6e38 commit 8d62755
Show file tree
Hide file tree
Showing 25 changed files with 2,987 additions and 163 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ crash.log
test.log

_templates/test/tests/__pycache__/

# make sure not to add any files here
examples/files
examples/files/**
examples/**/output.json
120 changes: 120 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ custom-readme:
docker run -it -v "$(shell pwd):/tmp/terraform-module" \
-e README_TEMPLATE_FILE=/tmp/terraform-module/README.md.gotmpl \
-w /tmp/terraform-module \
cloudposse/build-harness:slim-latest readme
cloudposse/build-harness:slim-latest readme

ec2builder/components:
aws imagebuilder get-component --component-build-version-arn arn:aws:imagebuilder:us-west-2:123456789012:component/my-example-component/2019.12.02/1
4 changes: 2 additions & 2 deletions _templates/terraform-cookiecutter/hooks/pre_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
import sys


MODULE_REGEX = r'^[_a-zA-Z][_a-zA-Z0-9]+$'
MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]+$"

module_name = '{{ cookiecutter.module_name }}'
module_name = "{{ cookiecutter.module_name }}"
22 changes: 11 additions & 11 deletions _templates/terraform-cookiecutter/hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import re
import sys

delimiter = '{{cookiecutter.delimiter}}'
delimiter = "{{cookiecutter.delimiter}}"

label_order = ["namespace", "environment", "stage", "name", "attributes"]
label_order = ["namespace", "environment", "stage", "name", "attributes"]
id_context = {
"namespace" : "{{ cookiecutter.namespace}}",
"tenant" : "{{cookiecutter.tenant}}",
"name" : "{{ cookiecutter.name}}",
"environment" : "{{cookiecutter.environment}}",
"stage" : "{{cookiecutter.stage}}",
"name" : "{{cookiecutter.name}}"
"namespace": "{{ cookiecutter.namespace}}",
"tenant": "{{cookiecutter.tenant}}",
"name": "{{ cookiecutter.name}}",
"environment": "{{cookiecutter.environment}}",
"stage": "{{cookiecutter.stage}}",
"name": "{{cookiecutter.name}}",
}

labels = []
Expand All @@ -20,10 +20,10 @@

id_full = delimiter.join(labels)

{{ cookiecutter.update({ "project_name": id_full }) }}
{{cookiecutter.update({"project_name": id_full})}}

from pprint import pprint

cookiecutter_context = {{ cookiecutter.__dict__ }}
cookiecutter_context = {{cookiecutter.__dict__}}
keys = cookiecutter_context.keys()
pprint(cookiecutter_context)
pprint(cookiecutter_context)
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@


def test_output():
logging.info(f'Writing some tests')
assert 1 == 1, print('did not succeed')
logging.info(f"Writing some tests")
assert 1 == 1, print("did not succeed")
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# This tool comes from - https://gist.github.com/tnwei/726d377410b9a6285ddc1b18c4e67dc6
# with thanks!


@click.command()
@click.argument("pathsource", default=".", type=Path)
@click.option("-o", "--outputdir", default="_build/html", type=Path, show_default=True)
Expand All @@ -35,32 +36,39 @@ def main(pathsource: Path, examplesdir: Path, outputdir: Path, port: int):
+ https://github.com/executablebooks/sphinx-autobuild/issues/99#issuecomment-722319104
+ mkdocs docs on github
"""

def gencookiecutter_dirs():
os.makedirs('_templates/module', mode = 0o777, exist_ok = False)
os.makedirs('_templates/examples', mode = 0o777, exist_ok = False)
examples = glob.glob('examples/*')
os.makedirs("_templates/module", mode=0o777, exist_ok=False)
os.makedirs("_templates/examples", mode=0o777, exist_ok=False)
examples = glob.glob("examples/*")
example_dirs = []
for example in examples:
if os.path.isdir(example) and example not in example_dirs:
example_dirs.append(example)

for example in example_dirs:
os.makedirs(f'_templates/{example}', mode = 0o777, exist_ok = False)
os.makedirs(f"_templates/{example}", mode=0o777, exist_ok=False)
return example_dirs

def gencookiecutters():
example_dirs = gencookiecutter_dirs()

def pygmentize():
terraform_files = glob.glob(f'{examplesdir}/**/**.tf', recursive=True)
terraform_files = glob.glob(f"{examplesdir}/**/**.tf", recursive=True)
for terraform_file in terraform_files:
dirname = os.path.dirname(terraform_file)
tf_html_dir = os.path.join(dirname, '_html')
tf_html_dir = os.path.join(dirname, "_html")
basename = os.path.basename(terraform_file)
tf_html_file = os.path.join(tf_html_dir, f"{basename}.html")
tf_html_file = os.path.join(tf_html_dir, f"{basename}.html")
if not os.path.exists(tf_html_dir):
subprocess.run(["mkdir", "-p", tf_html_dir])
subprocess.run(["bash", "-c", f"pygmentize -l terraform -f html {terraform_file} > {tf_html_file}"])
subprocess.run(
[
"bash",
"-c",
f"pygmentize -l terraform -f html {terraform_file} > {tf_html_file}",
]
)

def build():
subprocess.run(["jb", "clean", pathsource])
Expand All @@ -72,7 +80,7 @@ def build():

server = Server()

DELAY=10
DELAY = 10
# Globbing for all supported file types under examplesdir
server.watch(os.path.join(examplesdir, "**/**.tf"), pygmentize, delay=DELAY)
server.watch(os.path.join(examplesdir, "**/*.tf"), pygmentize, delay=DELAY)
Expand All @@ -86,7 +94,8 @@ def build():
server.watch(pathsource / "_config.yml", build)
server.watch(pathsource / "_toc.yml", build)

server.serve(root=outputdir, port=port, host='0.0.0.0')
server.serve(root=outputdir, port=port, host="0.0.0.0")


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@


def test_output():
logging.info(f'Writing some tests')
assert 1 == 1, print('did not succeed')
logging.info(f"Writing some tests")
assert 1 == 1, print("did not succeed")
4 changes: 2 additions & 2 deletions _templates/test/tests/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@


def test_output():
logging.info(f'Writing some tests')
assert 1 == 1, print('did not succeed')
logging.info(f"Writing some tests")
assert 1 == 1, print("did not succeed")
4 changes: 2 additions & 2 deletions _templates/tests/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@


def test_output():
logging.info(f'Writing some tests')
assert 1 == 1, print('did not succeed')
logging.info(f"Writing some tests")
assert 1 == 1, print("did not succeed")
Loading

0 comments on commit 8d62755

Please sign in to comment.