-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_generation.py
More file actions
93 lines (76 loc) · 2.42 KB
/
test_generation.py
File metadata and controls
93 lines (76 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Script de test pour la génération Terraform.
Ce script démontre comment utiliser le générateur Terraform :
1. Parse un fichier spec.json
2. Génère la configuration Terraform
3. Affiche les fichiers générés
Pour exécuter :
python test_generation.py
"""
import sys
from pathlib import Path
# Ajouter src au path Python
src_path = Path(__file__).parent / "src"
sys.path.insert(0, str(src_path))
# Imports
from validators.parser import SpecParser
from infrastructure.generators import generate_terraform_config
def main():
"""
Fonction principale qui teste la génération Terraform.
"""
print("=" * 60)
print("Test de génération Terraform")
print("=" * 60)
# Chemin vers un fichier spec.json de test
# Vous pouvez créer un fichier spec.json simple pour tester
spec_file = Path("spec.json")
if not spec_file.exists():
print(f"\n❌ Fichier {spec_file} non trouvé.")
print("\nCréez un fichier spec.json avec la structure suivante :")
print("""
{
"aws": {
"access_key": "YOUR_KEY",
"secret_key": "YOUR_SECRET",
"region": "us-east-1"
},
"infrastructure": {
"scalability": "MED",
"machine_size": "M",
"key_pair": "my-keypair"
},
"application": {
"services": [
{
"name": "backend",
"image": "nginx:latest",
"ports": [8080],
"type": "EC2"
}
]
}
}
""")
return
try:
# Étape 1 : Parser et valider le spec.json
print(f"\n📄 Étape 1 : Parsing de {spec_file}")
parser = SpecParser(spec_file)
spec = parser.parse()
# Étape 2 : Générer la configuration Terraform
print(f"\n🔧 Étape 2 : Génération de la configuration Terraform")
output_dir = generate_terraform_config(spec, output_dir="terraform_output")
# Étape 3 : Afficher les fichiers générés
print(f"\n📁 Étape 3 : Fichiers générés dans {output_dir}")
print("\nFichiers créés :")
for file in sorted(output_dir.glob("*.tf")):
print(f" - {file.name}")
print(f"\n✅ Test réussi ! Vous pouvez maintenant aller dans {output_dir}")
print(" et exécuter : terraform init && terraform plan")
except Exception as e:
print(f"\n❌ Erreur : {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
main()