Template generator from YAML to Python

34 views
Skip to first unread message

Frank

unread,
Nov 17, 2022, 8:22:04 AM11/17/22
to cloudtools-dev
Hi,

I'm trying to understand whether I can convert a YAML o JSON to Python, in this way I can use existing templates or customizing then in YAML, then to convert them to Python to build infra.

I have used the code example below without any luck.

Can you advise some tutorials or provide simple examples?., thanks in advanced.

from troposphere.template_generator import TemplateGenerator
import yaml

with open("vpc_template_convert.yml") as f:
source_content = yaml.load(f, Loader=yaml.BaseLoader)
template = TemplateGenerator(source_content)  

Frank

unread,
Nov 17, 2022, 9:44:19 AM11/17/22
to cloudtools-dev
I have found this below that I test and apparently does the job okay.

Any other suggestions?, cheers.

cfn-flip -c -j template-vpc.yaml template-vpc.json 

cfn2py template-vpc.json > template_vpc.py

Frank

unread,
Nov 21, 2022, 12:33:39 PM11/21/22
to cloudtools-dev
Hi,

I have applied the "usage" written in this file "https://github.com/cloudtools/troposphere/blob/main/troposphere/template_generator.py", I didn't get any output.

I was expecting to pass the json template name, then get to have a new .py file.

Is there anyone able to explain how the "template generator" works?, thanks.
Reply all
Reply to author
Forward
0 new messages