Skip to content

Commit 02c3645

Browse files
committed
feat(terraform-templates): implementing aws-rds route
1 parent e812033 commit 02c3645

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

app/media/terraform.tfvars

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
create = true
2-
create_private_key = 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,13 @@ class IaCTemplateGenerationKeyPair(BaseModel):
145145

146146
key_pair:bool = True
147147
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
IaCTemplateGenerationAutoScaling,
2222
IaCTemplateGenerationSQS,
2323
IaCTemplateGenerationRoute53,
24-
IaCTemplateGenerationKeyPair
24+
IaCTemplateGenerationKeyPair,
25+
IaCTemplateGenerationRDS
2526
)
2627

2728
from fastapi import Response
@@ -44,6 +45,7 @@
4445
from app.template_generators.terraform.aws.SQS import (IaC_template_generator_sqs)
4546
from app.template_generators.terraform.aws.Route53 import (IaC_template_generator_route53)
4647
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)
4749
from app.template_generators.terraform.Installation.main import (select_install)
4850
import os
4951

@@ -239,3 +241,15 @@ async def IaC_template_generation_aws_key_pair(request:IaCTemplateGenerationKeyP
239241

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

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: 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

0 commit comments

Comments
 (0)