Skip to content

Commit

Permalink
Merge pull request #166 from devopshobbies/dev
Browse files Browse the repository at this point in the history
feat(terraform-templates): implementing the routes of terraform-aws modules
  • Loading branch information
mohammadll authored Jan 18, 2025
2 parents ced2cb1 + 02c3645 commit dce2a82
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 6 deletions.
12 changes: 7 additions & 5 deletions app/media/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
create_distribution = true
create_origin_access_identity = true
create_origin_access_control = false
create_monitoring_subscription = false
create_vpc_origin = false
create_db_instance = true
create_db_option_group = true
create_db_parameter_group = true
create_db_subnet_group = true
create_monitoring_role = true
create_cloudwatch_log_group = true
manage_master_user_password_rotation = false
44 changes: 44 additions & 0 deletions app/models/terraform_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,47 @@ class IaCTemplateGenerationCloudFront(BaseModel):
origin_access_control:bool = False
monitoring_subscription:bool = False
vpc_origin:bool = False

class IaCTemplateGenerationSNS(BaseModel):

sns_topic:bool = True
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

class IaCTemplateGenerationSQS(BaseModel):

sqs_queue:bool = True
queue_policy:bool = False
dlq:bool = False
dlq_redrive_allow_policy:bool = True
dlq_queue_policy:bool = False

class IaCTemplateGenerationRoute53(BaseModel):

zone:bool = True
record:bool = True
delegation_set:bool = False
resolver_rule_association:bool = False

class IaCTemplateGenerationKeyPair(BaseModel):

key_pair:bool = True
private_key:bool = False

class IaCTemplateGenerationRDS(BaseModel):

db_instance:bool = True
db_option_group:bool = True
db_parameter_group:bool = True
db_subnet_group:bool = True
monitoring_role:bool = True
cloudwatch_log_group:bool = True
master_user_password_rotation:bool = False
86 changes: 85 additions & 1 deletion app/routes/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
IaCTemplateGenerationELB,
IaCTemplateGenerationEFS,
IaCTemplateGenerationALB,
IaCTemplateGenerationCloudFront
IaCTemplateGenerationCloudFront,
IaCTemplateGenerationSNS,
IaCTemplateGenerationAutoScaling,
IaCTemplateGenerationSQS,
IaCTemplateGenerationRoute53,
IaCTemplateGenerationKeyPair,
IaCTemplateGenerationRDS
)

from fastapi import Response
Expand All @@ -34,6 +40,12 @@
from app.template_generators.terraform.aws.EFS import (IaC_template_generator_efs)
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.aws.SQS import (IaC_template_generator_sqs)
from app.template_generators.terraform.aws.Route53 import (IaC_template_generator_route53)
from app.template_generators.terraform.aws.KeyPair import (IaC_template_generator_key_pair)
from app.template_generators.terraform.aws.RDS import (IaC_template_generator_rds)
from app.template_generators.terraform.Installation.main import (select_install)
import os

Expand Down Expand Up @@ -169,3 +181,75 @@ async def IaC_template_generation_aws_cloudfront(request:IaCTemplateGenerationCl

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


@app.post("/api/IaC-template/aws/sns")
async def IaC_template_generation_aws_sns(request:IaCTemplateGenerationSNS) -> Output:

dir = 'app/media/terraform.tfvars'

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

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")


@app.post("/api/IaC-template/aws/sqs")
async def IaC_template_generation_aws_sqs(request:IaCTemplateGenerationSQS) -> Output:

dir = 'app/media/terraform.tfvars'

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

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


@app.post("/api/IaC-template/aws/route53")
async def IaC_template_generation_aws_route53(request:IaCTemplateGenerationRoute53) -> Output:

dir = 'app/media/terraform.tfvars'

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

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


@app.post("/api/IaC-template/aws/key_pair")
async def IaC_template_generation_aws_key_pair(request:IaCTemplateGenerationKeyPair) -> Output:

dir = 'app/media/terraform.tfvars'

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

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


@app.post("/api/IaC-template/aws/rds")
async def IaC_template_generation_aws_rds(request:IaCTemplateGenerationRDS) -> Output:

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_rds(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
9 changes: 9 additions & 0 deletions app/template_generators/terraform/aws/KeyPair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def IaC_template_generator_key_pair(input) -> str:

aws_key_pair_create = 'true' if input.key_pair else 'false'
aws_key_pair_create_private_key = 'true' if input.private_key else 'false'

tfvars_file = f"""create = {aws_key_pair_create}
create_private_key = {aws_key_pair_create_private_key}
"""
return tfvars_file
19 changes: 19 additions & 0 deletions app/template_generators/terraform/aws/RDS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def IaC_template_generator_rds(input) -> str:

aws_rds_create_db_instance = 'true' if input.db_instance else 'false'
aws_rds_create_db_option_group = 'true' if input.db_option_group else 'false'
aws_rds_create_db_parameter_group = 'true' if input.db_parameter_group else 'false'
aws_rds_create_db_subnet_group = 'true' if input.db_subnet_group else 'false'
aws_rds_create_monitoring_role = 'true' if input.monitoring_role else 'false'
aws_rds_create_cloudwatch_log_group = 'true' if input.cloudwatch_log_group else 'false'
aws_rds_create_master_user_password_rotation = 'true' if input.master_user_password_rotation else 'false'

tfvars_file = f"""create_db_instance = {aws_rds_create_db_instance}
create_db_option_group = {aws_rds_create_db_option_group}
create_db_parameter_group = {aws_rds_create_db_parameter_group}
create_db_subnet_group = {aws_rds_create_db_subnet_group}
create_monitoring_role = {aws_rds_create_monitoring_role}
create_cloudwatch_log_group = {aws_rds_create_cloudwatch_log_group}
manage_master_user_password_rotation = {aws_rds_create_master_user_password_rotation}
"""
return tfvars_file
13 changes: 13 additions & 0 deletions app/template_generators/terraform/aws/Route53.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def IaC_template_generator_route53(input) -> str:

aws_route53_create_zone = 'true' if input.zone else 'false'
aws_route53_create_record = 'true' if input.record else 'false'
aws_route53_create_delegation_set = 'true' if input.delegation_set else 'false'
aws_route53_create_resolver_rule_association = 'true' if input.resolver_rule_association else 'false'

tfvars_file = f"""create_zone = {aws_route53_create_zone}
create_record = {aws_route53_create_record}
create_delegation_set = {aws_route53_create_delegation_set}
create_resolver_rule_association = {aws_route53_create_resolver_rule_association}
"""
return tfvars_file
11 changes: 11 additions & 0 deletions app/template_generators/terraform/aws/SNS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def IaC_template_generator_sns(input) -> str:

aws_sns_create_topic = 'true' if input.sns_topic else 'false'
aws_sns_create_topic_policy = 'true' if input.topic_policy else 'false'
aws_sns_create_subscription = 'true' if input.subscription else 'false'

tfvars_file = f"""create = {aws_sns_create_topic}
create_topic_policy = {aws_sns_create_topic_policy}
create_subscription = {aws_sns_create_subscription}
"""
return tfvars_file
15 changes: 15 additions & 0 deletions app/template_generators/terraform/aws/SQS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def IaC_template_generator_sqs(input) -> str:

aws_sqs_create_queue = 'true' if input.sqs_queue else 'false'
aws_sqs_create_queue_policy = 'true' if input.queue_policy else 'false'
aws_sqs_create_dlq = 'true' if input.dlq else 'false'
aws_sqs_create_dlq_redrive_allow_policy = 'true' if input.dlq_redrive_allow_policy else 'false'
aws_sqs_create_dlq_queue_policy = 'true' if input.dlq_queue_policy else 'false'

tfvars_file = f"""create = {aws_sqs_create_queue}
create_queue_policy = {aws_sqs_create_queue_policy}
create_dlq = {aws_sqs_create_dlq}
create_dlq_redrive_allow_policy = {aws_sqs_create_dlq_redrive_allow_policy}
create_dlq_queue_policy = {aws_sqs_create_dlq_queue_policy}
"""
return tfvars_file

0 comments on commit dce2a82

Please sign in to comment.