Skip to content

Commit dce2a82

Browse files
authored
Merge pull request #166 from devopshobbies/dev
feat(terraform-templates): implementing the routes of terraform-aws modules
2 parents ced2cb1 + 02c3645 commit dce2a82

File tree

9 files changed

+218
-6
lines changed

9 files changed

+218
-6
lines changed

app/media/terraform.tfvars

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
create_distribution = true
2-
create_origin_access_identity = true
3-
create_origin_access_control = false
4-
create_monitoring_subscription = false
5-
create_vpc_origin = false
1+
create_db_instance = true
2+
create_db_option_group = true
3+
create_db_parameter_group = true
4+
create_db_subnet_group = true
5+
create_monitoring_role = true
6+
create_cloudwatch_log_group = true
7+
manage_master_user_password_rotation = false

app/models/terraform_models.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,47 @@ class IaCTemplateGenerationCloudFront(BaseModel):
111111
origin_access_control:bool = False
112112
monitoring_subscription:bool = False
113113
vpc_origin:bool = False
114+
115+
class IaCTemplateGenerationSNS(BaseModel):
116+
117+
sns_topic:bool = True
118+
topic_policy:bool = True
119+
subscription:bool = True
120+
121+
class IaCTemplateGenerationAutoScaling(BaseModel):
122+
123+
autoscaling_group:bool = True
124+
launch_template:bool = True
125+
schedule:bool = True
126+
scaling_policy:bool = True
127+
iam_instance_profile:bool = True
128+
129+
class IaCTemplateGenerationSQS(BaseModel):
130+
131+
sqs_queue:bool = True
132+
queue_policy:bool = False
133+
dlq:bool = False
134+
dlq_redrive_allow_policy:bool = True
135+
dlq_queue_policy:bool = False
136+
137+
class IaCTemplateGenerationRoute53(BaseModel):
138+
139+
zone:bool = True
140+
record:bool = True
141+
delegation_set:bool = False
142+
resolver_rule_association:bool = False
143+
144+
class IaCTemplateGenerationKeyPair(BaseModel):
145+
146+
key_pair:bool = True
147+
private_key:bool = False
148+
149+
class IaCTemplateGenerationRDS(BaseModel):
150+
151+
db_instance:bool = True
152+
db_option_group:bool = True
153+
db_parameter_group:bool = True
154+
db_subnet_group:bool = True
155+
monitoring_role:bool = True
156+
cloudwatch_log_group:bool = True
157+
master_user_password_rotation:bool = False

app/routes/terraform.py

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
IaCTemplateGenerationELB,
1717
IaCTemplateGenerationEFS,
1818
IaCTemplateGenerationALB,
19-
IaCTemplateGenerationCloudFront
19+
IaCTemplateGenerationCloudFront,
20+
IaCTemplateGenerationSNS,
21+
IaCTemplateGenerationAutoScaling,
22+
IaCTemplateGenerationSQS,
23+
IaCTemplateGenerationRoute53,
24+
IaCTemplateGenerationKeyPair,
25+
IaCTemplateGenerationRDS
2026
)
2127

2228
from fastapi import Response
@@ -34,6 +40,12 @@
3440
from app.template_generators.terraform.aws.EFS import (IaC_template_generator_efs)
3541
from app.template_generators.terraform.aws.ALB import (IaC_template_generator_alb)
3642
from app.template_generators.terraform.aws.CloudFront import (IaC_template_generator_cloudfront)
43+
from app.template_generators.terraform.aws.SNS import (IaC_template_generator_sns)
44+
from app.template_generators.terraform.aws.AutoScaling import (IaC_template_generator_autoscaling)
45+
from app.template_generators.terraform.aws.SQS import (IaC_template_generator_sqs)
46+
from app.template_generators.terraform.aws.Route53 import (IaC_template_generator_route53)
47+
from app.template_generators.terraform.aws.KeyPair import (IaC_template_generator_key_pair)
48+
from app.template_generators.terraform.aws.RDS import (IaC_template_generator_rds)
3749
from app.template_generators.terraform.Installation.main import (select_install)
3850
import os
3951

@@ -169,3 +181,75 @@ async def IaC_template_generation_aws_cloudfront(request:IaCTemplateGenerationCl
169181

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

184+
185+
@app.post("/api/IaC-template/aws/sns")
186+
async def IaC_template_generation_aws_sns(request:IaCTemplateGenerationSNS) -> Output:
187+
188+
dir = 'app/media/terraform.tfvars'
189+
190+
file_response = IaC_template_generator_sns(request)
191+
with open(dir,'w')as f:
192+
f.write(file_response)
193+
194+
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
195+
196+
197+
@app.post("/api/IaC-template/aws/autoscaling")
198+
async def IaC_template_generation_aws_autoscaling(request:IaCTemplateGenerationAutoScaling) -> Output:
199+
200+
dir = 'app/media/terraform.tfvars'
201+
202+
file_response = IaC_template_generator_autoscaling(request)
203+
with open(dir,'w')as f:
204+
f.write(file_response)
205+
206+
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
207+
208+
209+
@app.post("/api/IaC-template/aws/sqs")
210+
async def IaC_template_generation_aws_sqs(request:IaCTemplateGenerationSQS) -> Output:
211+
212+
dir = 'app/media/terraform.tfvars'
213+
214+
file_response = IaC_template_generator_sqs(request)
215+
with open(dir,'w')as f:
216+
f.write(file_response)
217+
218+
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
219+
220+
221+
@app.post("/api/IaC-template/aws/route53")
222+
async def IaC_template_generation_aws_route53(request:IaCTemplateGenerationRoute53) -> Output:
223+
224+
dir = 'app/media/terraform.tfvars'
225+
226+
file_response = IaC_template_generator_route53(request)
227+
with open(dir,'w')as f:
228+
f.write(file_response)
229+
230+
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
231+
232+
233+
@app.post("/api/IaC-template/aws/key_pair")
234+
async def IaC_template_generation_aws_key_pair(request:IaCTemplateGenerationKeyPair) -> Output:
235+
236+
dir = 'app/media/terraform.tfvars'
237+
238+
file_response = IaC_template_generator_key_pair(request)
239+
with open(dir,'w')as f:
240+
f.write(file_response)
241+
242+
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
243+
244+
245+
@app.post("/api/IaC-template/aws/rds")
246+
async def IaC_template_generation_aws_rds(request:IaCTemplateGenerationRDS) -> Output:
247+
248+
dir = 'app/media/terraform.tfvars'
249+
250+
file_response = IaC_template_generator_rds(request)
251+
with open(dir,'w')as f:
252+
f.write(file_response)
253+
254+
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
255+
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
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def IaC_template_generator_key_pair(input) -> str:
2+
3+
aws_key_pair_create = 'true' if input.key_pair else 'false'
4+
aws_key_pair_create_private_key = 'true' if input.private_key else 'false'
5+
6+
tfvars_file = f"""create = {aws_key_pair_create}
7+
create_private_key = {aws_key_pair_create_private_key}
8+
"""
9+
return tfvars_file
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def IaC_template_generator_rds(input) -> str:
2+
3+
aws_rds_create_db_instance = 'true' if input.db_instance else 'false'
4+
aws_rds_create_db_option_group = 'true' if input.db_option_group else 'false'
5+
aws_rds_create_db_parameter_group = 'true' if input.db_parameter_group else 'false'
6+
aws_rds_create_db_subnet_group = 'true' if input.db_subnet_group else 'false'
7+
aws_rds_create_monitoring_role = 'true' if input.monitoring_role else 'false'
8+
aws_rds_create_cloudwatch_log_group = 'true' if input.cloudwatch_log_group else 'false'
9+
aws_rds_create_master_user_password_rotation = 'true' if input.master_user_password_rotation else 'false'
10+
11+
tfvars_file = f"""create_db_instance = {aws_rds_create_db_instance}
12+
create_db_option_group = {aws_rds_create_db_option_group}
13+
create_db_parameter_group = {aws_rds_create_db_parameter_group}
14+
create_db_subnet_group = {aws_rds_create_db_subnet_group}
15+
create_monitoring_role = {aws_rds_create_monitoring_role}
16+
create_cloudwatch_log_group = {aws_rds_create_cloudwatch_log_group}
17+
manage_master_user_password_rotation = {aws_rds_create_master_user_password_rotation}
18+
"""
19+
return tfvars_file
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def IaC_template_generator_route53(input) -> str:
2+
3+
aws_route53_create_zone = 'true' if input.zone else 'false'
4+
aws_route53_create_record = 'true' if input.record else 'false'
5+
aws_route53_create_delegation_set = 'true' if input.delegation_set else 'false'
6+
aws_route53_create_resolver_rule_association = 'true' if input.resolver_rule_association else 'false'
7+
8+
tfvars_file = f"""create_zone = {aws_route53_create_zone}
9+
create_record = {aws_route53_create_record}
10+
create_delegation_set = {aws_route53_create_delegation_set}
11+
create_resolver_rule_association = {aws_route53_create_resolver_rule_association}
12+
"""
13+
return tfvars_file
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def IaC_template_generator_sns(input) -> str:
2+
3+
aws_sns_create_topic = 'true' if input.sns_topic else 'false'
4+
aws_sns_create_topic_policy = 'true' if input.topic_policy else 'false'
5+
aws_sns_create_subscription = 'true' if input.subscription else 'false'
6+
7+
tfvars_file = f"""create = {aws_sns_create_topic}
8+
create_topic_policy = {aws_sns_create_topic_policy}
9+
create_subscription = {aws_sns_create_subscription}
10+
"""
11+
return tfvars_file
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def IaC_template_generator_sqs(input) -> str:
2+
3+
aws_sqs_create_queue = 'true' if input.sqs_queue else 'false'
4+
aws_sqs_create_queue_policy = 'true' if input.queue_policy else 'false'
5+
aws_sqs_create_dlq = 'true' if input.dlq else 'false'
6+
aws_sqs_create_dlq_redrive_allow_policy = 'true' if input.dlq_redrive_allow_policy else 'false'
7+
aws_sqs_create_dlq_queue_policy = 'true' if input.dlq_queue_policy else 'false'
8+
9+
tfvars_file = f"""create = {aws_sqs_create_queue}
10+
create_queue_policy = {aws_sqs_create_queue_policy}
11+
create_dlq = {aws_sqs_create_dlq}
12+
create_dlq_redrive_allow_policy = {aws_sqs_create_dlq_redrive_allow_policy}
13+
create_dlq_queue_policy = {aws_sqs_create_dlq_queue_policy}
14+
"""
15+
return tfvars_file

0 commit comments

Comments
 (0)