Skip to content

Commit 98e107c

Browse files
committed
feat(terraform-templates): implementing aws-autoscaling route
1 parent ab551a1 commit 98e107c

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

app/media/terraform.tfvars

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
create = true
2-
fifo_topic = false
3-
create_topic_policy = true
4-
create_subscription = true
2+
create_launch_template = true
3+
create_schedule = true
4+
create_scaling_policy = true
5+
create_iam_instance_profile = true

app/models/terraform_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,11 @@ class IaCTemplateGenerationSNS(BaseModel):
118118
fifo_topic:bool = False
119119
topic_policy:bool = True
120120
subscription:bool = True
121+
122+
class IaCTemplateGenerationAutoScaling(BaseModel):
123+
124+
autoscaling_group:bool = True
125+
launch_template:bool = True
126+
schedule:bool = True
127+
scaling_policy:bool = True
128+
iam_instance_profile:bool = True

app/routes/terraform.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
IaCTemplateGenerationEFS,
1818
IaCTemplateGenerationALB,
1919
IaCTemplateGenerationCloudFront,
20-
IaCTemplateGenerationSNS
20+
IaCTemplateGenerationSNS,
21+
IaCTemplateGenerationAutoScaling
2122
)
2223

2324
from fastapi import Response
@@ -36,6 +37,7 @@
3637
from app.template_generators.terraform.aws.ALB import (IaC_template_generator_alb)
3738
from app.template_generators.terraform.aws.CloudFront import (IaC_template_generator_cloudfront)
3839
from app.template_generators.terraform.aws.SNS import (IaC_template_generator_sns)
40+
from app.template_generators.terraform.aws.AutoScaling import (IaC_template_generator_autoscaling)
3941
from app.template_generators.terraform.Installation.main import (select_install)
4042
import os
4143

@@ -183,3 +185,15 @@ async def IaC_template_generation_aws_sns(request:IaCTemplateGenerationSNS) -> O
183185

184186
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
185187

188+
189+
@app.post("/api/IaC-template/aws/autoscaling")
190+
async def IaC_template_generation_aws_autoscaling(request:IaCTemplateGenerationAutoScaling) -> Output:
191+
192+
dir = 'app/media/terraform.tfvars'
193+
194+
file_response = IaC_template_generator_autoscaling(request)
195+
with open(dir,'w')as f:
196+
f.write(file_response)
197+
198+
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
199+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def IaC_template_generator_autoscaling(input) -> str:
2+
3+
aws_autoscaling_create_group = 'true' if input.autoscaling_group else 'false'
4+
aws_autoscaling_create_launch_template = 'true' if input.launch_template else 'false'
5+
aws_autoscaling_create_schedule = 'true' if input.schedule else 'false'
6+
aws_autoscaling_create_scaling_policy = 'true' if input.scaling_policy else 'false'
7+
aws_autoscaling_create_iam_instance_profile = 'true' if input.iam_instance_profile else 'false'
8+
9+
tfvars_file = f"""create = {aws_autoscaling_create_group}
10+
create_launch_template = {aws_autoscaling_create_launch_template}
11+
create_schedule = {aws_autoscaling_create_schedule}
12+
create_scaling_policy = {aws_autoscaling_create_scaling_policy}
13+
create_iam_instance_profile = {aws_autoscaling_create_iam_instance_profile}
14+
"""
15+
return tfvars_file

0 commit comments

Comments
 (0)