Skip to content

Commit

Permalink
feat(terraform-templates): implementing aws-autoscaling route
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadll committed Jan 7, 2025
1 parent ab551a1 commit 98e107c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/media/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
create = true
fifo_topic = false
create_topic_policy = true
create_subscription = true
create_launch_template = true
create_schedule = true
create_scaling_policy = true
create_iam_instance_profile = true
8 changes: 8 additions & 0 deletions app/models/terraform_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ class IaCTemplateGenerationSNS(BaseModel):
fifo_topic:bool = False
topic_policy:bool = True
subscription:bool = True

class IaCTemplateGenerationAutoScaling(BaseModel):

autoscaling_group:bool = True
launch_template:bool = True
schedule:bool = True
scaling_policy:bool = True
iam_instance_profile:bool = True
16 changes: 15 additions & 1 deletion app/routes/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
IaCTemplateGenerationEFS,
IaCTemplateGenerationALB,
IaCTemplateGenerationCloudFront,
IaCTemplateGenerationSNS
IaCTemplateGenerationSNS,
IaCTemplateGenerationAutoScaling
)

from fastapi import Response
Expand All @@ -36,6 +37,7 @@
from app.template_generators.terraform.aws.ALB import (IaC_template_generator_alb)
from app.template_generators.terraform.aws.CloudFront import (IaC_template_generator_cloudfront)
from app.template_generators.terraform.aws.SNS import (IaC_template_generator_sns)
from app.template_generators.terraform.aws.AutoScaling import (IaC_template_generator_autoscaling)
from app.template_generators.terraform.Installation.main import (select_install)
import os

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

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


@app.post("/api/IaC-template/aws/autoscaling")
async def IaC_template_generation_aws_autoscaling(request:IaCTemplateGenerationAutoScaling) -> Output:

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_autoscaling(request)
with open(dir,'w')as f:
f.write(file_response)

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

15 changes: 15 additions & 0 deletions app/template_generators/terraform/aws/AutoScaling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def IaC_template_generator_autoscaling(input) -> str:

aws_autoscaling_create_group = 'true' if input.autoscaling_group else 'false'
aws_autoscaling_create_launch_template = 'true' if input.launch_template else 'false'
aws_autoscaling_create_schedule = 'true' if input.schedule else 'false'
aws_autoscaling_create_scaling_policy = 'true' if input.scaling_policy else 'false'
aws_autoscaling_create_iam_instance_profile = 'true' if input.iam_instance_profile else 'false'

tfvars_file = f"""create = {aws_autoscaling_create_group}
create_launch_template = {aws_autoscaling_create_launch_template}
create_schedule = {aws_autoscaling_create_schedule}
create_scaling_policy = {aws_autoscaling_create_scaling_policy}
create_iam_instance_profile = {aws_autoscaling_create_iam_instance_profile}
"""
return tfvars_file

0 comments on commit 98e107c

Please sign in to comment.