From ab551a19552c6dae9458a31525f18e65075fa859 Mon Sep 17 00:00:00 2001 From: mohammadll Date: Mon, 6 Jan 2025 13:55:53 +0330 Subject: [PATCH 1/7] feat(terraform-templates): implementing aws-sns route --- app/media/terraform.tfvars | 9 ++++----- app/models/terraform_models.py | 7 +++++++ app/routes/terraform.py | 16 +++++++++++++++- app/template_generators/terraform/aws/SNS.py | 13 +++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 app/template_generators/terraform/aws/SNS.py diff --git a/app/media/terraform.tfvars b/app/media/terraform.tfvars index de49d73..0a6c8fe 100644 --- a/app/media/terraform.tfvars +++ b/app/media/terraform.tfvars @@ -1,5 +1,4 @@ -create_distribution = true -create_origin_access_identity = true -create_origin_access_control = false -create_monitoring_subscription = false -create_vpc_origin = false +create = true +fifo_topic = false +create_topic_policy = true +create_subscription = true diff --git a/app/models/terraform_models.py b/app/models/terraform_models.py index 075ff4e..be3b472 100644 --- a/app/models/terraform_models.py +++ b/app/models/terraform_models.py @@ -111,3 +111,10 @@ class IaCTemplateGenerationCloudFront(BaseModel): origin_access_control:bool = False monitoring_subscription:bool = False vpc_origin:bool = False + +class IaCTemplateGenerationSNS(BaseModel): + + sns_topic:bool = True + fifo_topic:bool = False + topic_policy:bool = True + subscription:bool = True diff --git a/app/routes/terraform.py b/app/routes/terraform.py index 7585015..b50a07f 100644 --- a/app/routes/terraform.py +++ b/app/routes/terraform.py @@ -16,7 +16,8 @@ IaCTemplateGenerationELB, IaCTemplateGenerationEFS, IaCTemplateGenerationALB, - IaCTemplateGenerationCloudFront + IaCTemplateGenerationCloudFront, + IaCTemplateGenerationSNS ) from fastapi import Response @@ -34,6 +35,7 @@ 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.Installation.main import (select_install) import os @@ -169,3 +171,15 @@ 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") + diff --git a/app/template_generators/terraform/aws/SNS.py b/app/template_generators/terraform/aws/SNS.py new file mode 100644 index 0000000..9e466fc --- /dev/null +++ b/app/template_generators/terraform/aws/SNS.py @@ -0,0 +1,13 @@ +def IaC_template_generator_sns(input) -> str: + + aws_sns_create_topic = 'true' if input.sns_topic else 'false' + aws_sns_create_fifo_topic = 'true' if input.fifo_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} +fifo_topic = {aws_sns_create_fifo_topic} +create_topic_policy = {aws_sns_create_topic_policy} +create_subscription = {aws_sns_create_subscription} +""" + return tfvars_file From 98e107ca43597722459396e017d317fcd901ae1c Mon Sep 17 00:00:00 2001 From: mohammadll Date: Tue, 7 Jan 2025 11:41:14 +0330 Subject: [PATCH 2/7] feat(terraform-templates): implementing aws-autoscaling route --- app/media/terraform.tfvars | 7 ++++--- app/models/terraform_models.py | 8 ++++++++ app/routes/terraform.py | 16 +++++++++++++++- .../terraform/aws/AutoScaling.py | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 app/template_generators/terraform/aws/AutoScaling.py diff --git a/app/media/terraform.tfvars b/app/media/terraform.tfvars index 0a6c8fe..d656027 100644 --- a/app/media/terraform.tfvars +++ b/app/media/terraform.tfvars @@ -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 diff --git a/app/models/terraform_models.py b/app/models/terraform_models.py index be3b472..817f442 100644 --- a/app/models/terraform_models.py +++ b/app/models/terraform_models.py @@ -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 diff --git a/app/routes/terraform.py b/app/routes/terraform.py index b50a07f..f41a635 100644 --- a/app/routes/terraform.py +++ b/app/routes/terraform.py @@ -17,7 +17,8 @@ IaCTemplateGenerationEFS, IaCTemplateGenerationALB, IaCTemplateGenerationCloudFront, - IaCTemplateGenerationSNS + IaCTemplateGenerationSNS, + IaCTemplateGenerationAutoScaling ) from fastapi import Response @@ -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 @@ -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") + diff --git a/app/template_generators/terraform/aws/AutoScaling.py b/app/template_generators/terraform/aws/AutoScaling.py new file mode 100644 index 0000000..d2245e1 --- /dev/null +++ b/app/template_generators/terraform/aws/AutoScaling.py @@ -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 From 907ca703f9faa36515d1e59c83360dce0d6bcd9a Mon Sep 17 00:00:00 2001 From: mohammadll Date: Wed, 8 Jan 2025 20:24:06 +0330 Subject: [PATCH 3/7] feat(terraform-templates): implementing aws-sqs route --- app/media/terraform.tfvars | 8 ++++---- app/models/terraform_models.py | 8 ++++++++ app/routes/terraform.py | 16 +++++++++++++++- app/template_generators/terraform/aws/SQS.py | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 app/template_generators/terraform/aws/SQS.py diff --git a/app/media/terraform.tfvars b/app/media/terraform.tfvars index d656027..998ce56 100644 --- a/app/media/terraform.tfvars +++ b/app/media/terraform.tfvars @@ -1,5 +1,5 @@ create = true -create_launch_template = true -create_schedule = true -create_scaling_policy = true -create_iam_instance_profile = true +create_queue_policy = false +create_dlq = false +create_dlq_redrive_allow_policy = true +create_dlq_queue_policy = false diff --git a/app/models/terraform_models.py b/app/models/terraform_models.py index 817f442..4b15deb 100644 --- a/app/models/terraform_models.py +++ b/app/models/terraform_models.py @@ -126,3 +126,11 @@ class IaCTemplateGenerationAutoScaling(BaseModel): 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 diff --git a/app/routes/terraform.py b/app/routes/terraform.py index f41a635..31a76eb 100644 --- a/app/routes/terraform.py +++ b/app/routes/terraform.py @@ -18,7 +18,8 @@ IaCTemplateGenerationALB, IaCTemplateGenerationCloudFront, IaCTemplateGenerationSNS, - IaCTemplateGenerationAutoScaling + IaCTemplateGenerationAutoScaling, + IaCTemplateGenerationSQS ) from fastapi import Response @@ -38,6 +39,7 @@ 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.Installation.main import (select_install) import os @@ -197,3 +199,15 @@ async def IaC_template_generation_aws_autoscaling(request:IaCTemplateGenerationA 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") + diff --git a/app/template_generators/terraform/aws/SQS.py b/app/template_generators/terraform/aws/SQS.py new file mode 100644 index 0000000..305c584 --- /dev/null +++ b/app/template_generators/terraform/aws/SQS.py @@ -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 From f9233b3fa3e92deea8b380dd6c013156db4933c7 Mon Sep 17 00:00:00 2001 From: mohammadll Date: Thu, 9 Jan 2025 13:38:42 +0330 Subject: [PATCH 4/7] feat(terraform-templates): implementing aws-route53 route --- app/media/terraform.tfvars | 9 ++++----- app/models/terraform_models.py | 7 +++++++ app/routes/terraform.py | 16 +++++++++++++++- app/template_generators/terraform/aws/Route53.py | 13 +++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 app/template_generators/terraform/aws/Route53.py diff --git a/app/media/terraform.tfvars b/app/media/terraform.tfvars index 998ce56..427eec2 100644 --- a/app/media/terraform.tfvars +++ b/app/media/terraform.tfvars @@ -1,5 +1,4 @@ -create = true -create_queue_policy = false -create_dlq = false -create_dlq_redrive_allow_policy = true -create_dlq_queue_policy = false +create_zone = true +create_record = true +create_delegation_set = false +create_resolver_rule_association = false diff --git a/app/models/terraform_models.py b/app/models/terraform_models.py index 4b15deb..8dd471e 100644 --- a/app/models/terraform_models.py +++ b/app/models/terraform_models.py @@ -134,3 +134,10 @@ class IaCTemplateGenerationSQS(BaseModel): 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 diff --git a/app/routes/terraform.py b/app/routes/terraform.py index 31a76eb..053b723 100644 --- a/app/routes/terraform.py +++ b/app/routes/terraform.py @@ -19,7 +19,8 @@ IaCTemplateGenerationCloudFront, IaCTemplateGenerationSNS, IaCTemplateGenerationAutoScaling, - IaCTemplateGenerationSQS + IaCTemplateGenerationSQS, + IaCTemplateGenerationRoute53 ) from fastapi import Response @@ -40,6 +41,7 @@ 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.Installation.main import (select_install) import os @@ -211,3 +213,15 @@ async def IaC_template_generation_aws_sqs(request:IaCTemplateGenerationSQS) -> O 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") + diff --git a/app/template_generators/terraform/aws/Route53.py b/app/template_generators/terraform/aws/Route53.py new file mode 100644 index 0000000..1b9f3b6 --- /dev/null +++ b/app/template_generators/terraform/aws/Route53.py @@ -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 From 13f93563f643b72d76e001dfcba0c268e95f5462 Mon Sep 17 00:00:00 2001 From: mohammadll Date: Thu, 9 Jan 2025 20:11:51 +0330 Subject: [PATCH 5/7] feat(terraform-templates): implementing aws-key-pair route --- app/media/terraform.tfvars | 6 ++---- app/models/terraform_models.py | 5 +++++ app/routes/terraform.py | 16 +++++++++++++++- app/template_generators/terraform/aws/KeyPair.py | 9 +++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 app/template_generators/terraform/aws/KeyPair.py diff --git a/app/media/terraform.tfvars b/app/media/terraform.tfvars index 427eec2..2458ddc 100644 --- a/app/media/terraform.tfvars +++ b/app/media/terraform.tfvars @@ -1,4 +1,2 @@ -create_zone = true -create_record = true -create_delegation_set = false -create_resolver_rule_association = false +create = true +create_private_key = false diff --git a/app/models/terraform_models.py b/app/models/terraform_models.py index 8dd471e..41f7db8 100644 --- a/app/models/terraform_models.py +++ b/app/models/terraform_models.py @@ -141,3 +141,8 @@ class IaCTemplateGenerationRoute53(BaseModel): record:bool = True delegation_set:bool = False resolver_rule_association:bool = False + +class IaCTemplateGenerationKeyPair(BaseModel): + + key_pair:bool = True + private_key:bool = False diff --git a/app/routes/terraform.py b/app/routes/terraform.py index 053b723..d4052c7 100644 --- a/app/routes/terraform.py +++ b/app/routes/terraform.py @@ -20,7 +20,8 @@ IaCTemplateGenerationSNS, IaCTemplateGenerationAutoScaling, IaCTemplateGenerationSQS, - IaCTemplateGenerationRoute53 + IaCTemplateGenerationRoute53, + IaCTemplateGenerationKeyPair ) from fastapi import Response @@ -42,6 +43,7 @@ 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.Installation.main import (select_install) import os @@ -225,3 +227,15 @@ async def IaC_template_generation_aws_route53(request:IaCTemplateGenerationRoute 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") + diff --git a/app/template_generators/terraform/aws/KeyPair.py b/app/template_generators/terraform/aws/KeyPair.py new file mode 100644 index 0000000..341648e --- /dev/null +++ b/app/template_generators/terraform/aws/KeyPair.py @@ -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 From e81203393e5e91390c59e5c23d267f965f649b18 Mon Sep 17 00:00:00 2001 From: mohammadll Date: Mon, 13 Jan 2025 14:09:20 +0330 Subject: [PATCH 6/7] fix(terraform-templates): removing fifo_topic from aws-sns model --- app/models/terraform_models.py | 1 - app/template_generators/terraform/aws/SNS.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/app/models/terraform_models.py b/app/models/terraform_models.py index 41f7db8..05ea49f 100644 --- a/app/models/terraform_models.py +++ b/app/models/terraform_models.py @@ -115,7 +115,6 @@ class IaCTemplateGenerationCloudFront(BaseModel): class IaCTemplateGenerationSNS(BaseModel): sns_topic:bool = True - fifo_topic:bool = False topic_policy:bool = True subscription:bool = True diff --git a/app/template_generators/terraform/aws/SNS.py b/app/template_generators/terraform/aws/SNS.py index 9e466fc..ac8370c 100644 --- a/app/template_generators/terraform/aws/SNS.py +++ b/app/template_generators/terraform/aws/SNS.py @@ -1,12 +1,10 @@ def IaC_template_generator_sns(input) -> str: aws_sns_create_topic = 'true' if input.sns_topic else 'false' - aws_sns_create_fifo_topic = 'true' if input.fifo_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} -fifo_topic = {aws_sns_create_fifo_topic} create_topic_policy = {aws_sns_create_topic_policy} create_subscription = {aws_sns_create_subscription} """ From 02c3645ffe00047d3adac21adbc05e981cbcd2c2 Mon Sep 17 00:00:00 2001 From: mohammadll Date: Mon, 13 Jan 2025 15:17:10 +0330 Subject: [PATCH 7/7] feat(terraform-templates): implementing aws-rds route --- app/media/terraform.tfvars | 9 +++++++-- app/models/terraform_models.py | 10 ++++++++++ app/routes/terraform.py | 16 +++++++++++++++- app/template_generators/terraform/aws/RDS.py | 19 +++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 app/template_generators/terraform/aws/RDS.py diff --git a/app/media/terraform.tfvars b/app/media/terraform.tfvars index 2458ddc..f5c421a 100644 --- a/app/media/terraform.tfvars +++ b/app/media/terraform.tfvars @@ -1,2 +1,7 @@ -create = true -create_private_key = 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 diff --git a/app/models/terraform_models.py b/app/models/terraform_models.py index 05ea49f..4aec74d 100644 --- a/app/models/terraform_models.py +++ b/app/models/terraform_models.py @@ -145,3 +145,13 @@ 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 diff --git a/app/routes/terraform.py b/app/routes/terraform.py index d4052c7..f8b5514 100644 --- a/app/routes/terraform.py +++ b/app/routes/terraform.py @@ -21,7 +21,8 @@ IaCTemplateGenerationAutoScaling, IaCTemplateGenerationSQS, IaCTemplateGenerationRoute53, - IaCTemplateGenerationKeyPair + IaCTemplateGenerationKeyPair, + IaCTemplateGenerationRDS ) from fastapi import Response @@ -44,6 +45,7 @@ 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 @@ -239,3 +241,15 @@ async def IaC_template_generation_aws_key_pair(request:IaCTemplateGenerationKeyP 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") + diff --git a/app/template_generators/terraform/aws/RDS.py b/app/template_generators/terraform/aws/RDS.py new file mode 100644 index 0000000..68e31df --- /dev/null +++ b/app/template_generators/terraform/aws/RDS.py @@ -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