def main()

in infra/build/developer-tools/build/scripts/task_wrapper_scripts/generate_modules.py [0:0]


def main(argv):
    modules = json.loads(argv[1])
    for module in modules:
        template_folder = module["template_folder"]
        module = Module(module["path"], module["options"])
        env = Environment(
            keep_trailing_newline=True,
            loader=FileSystemLoader(template_folder),
            trim_blocks=True,
            lstrip_blocks=True,
        )
        templates = env.list_templates()

        for template_file in templates:
            template = env.get_template(template_file)
            if template_file.endswith(".tf.tmpl"):
                template_file = template_file.replace(".tf.tmpl", ".tf")
            rendered = template.render(
                module.template_options(
                    {'autogeneration_note': AUTOGEN_NOTE.format(folder=template_folder)}
                )
            )
            with open(os.path.join(module.path, template_file), "w") as f:
                f.write(rendered)
                if template_file.endswith(".tf"):
                    subprocess.call(
                        [
                            "terraform",
                            "fmt",
                            "-write=true",
                            os.path.join(module.path, template_file)
                        ],
                        stdout=DEVNULL_FILE,
                        stderr=subprocess.STDOUT
                    )
                if template_file.endswith(".sh"):
                    os.chmod(os.path.join(module.path, template_file), 0o755)
    DEVNULL_FILE.close()