Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
abalij
/
terraform_doc_generate
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
423614bd
...
423614bdb2e0582aa3163a10a45d9f040be8527c
authored
2025-03-13 17:28:44 +0100
by
sitbon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add doc terraform
0 parents
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
generate_readme.py
generate_readme.py
0 → 100644
View file @
423614b
import
os
import
subprocess
# Récupérer le nom du module (nom du dossier actuel)
module_name
=
os
.
path
.
basename
(
os
.
getcwd
())
# Vérifier si terraform-docs est installé
try
:
subprocess
.
run
([
"terraform-docs"
,
"--version"
],
check
=
True
,
stdout
=
subprocess
.
PIPE
)
except
FileNotFoundError
:
print
(
"❌ terraform-docs n'est pas installé. Installez-le d'abord."
)
exit
(
1
)
# Exécuter terraform-docs et récupérer la sortie
terraform_docs_output
=
subprocess
.
run
([
"terraform-docs"
,
"markdown"
,
"."
],
capture_output
=
True
,
text
=
True
)
# Conditionner le comportement pour le README.md racine
if
module_name
==
"racine"
:
# Changez "racine" par le nom du dossier racine
# Pour la racine, on génère simplement un README propre sans les balises
readme_content
=
f
"# Projet Terraform
\n\n
{terraform_docs_output.stdout}"
else
:
# Pour les autres modules, on génère avec les balises
readme_content
=
f
"""<!-- BEGIN_TF_DOCS -->
# Module: {module_name}
{terraform_docs_output.stdout}
<!-- END_TF_DOCS -->
"""
# Écrire dans le fichier README.md
with
open
(
"README.md"
,
"w"
,
encoding
=
"utf-8"
)
as
readme_file
:
readme_file
.
write
(
readme_content
)
print
(
f
"✅ README.md généré pour le module {module_name} !"
)
Please
register
or
sign in
to post a comment