Skip to content

Commit 7b0abf6

Browse files
committed
feat(terraform-templates): implementing aws-cloudfront route
1 parent 7aa6583 commit 7b0abf6

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

app/media/terraform.tfvars

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
alb_create = true
2-
create_security_group = true
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

app/models/terraform_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,11 @@ class IaCTemplateGenerationALB(BaseModel):
103103

104104
alb_resources:bool = True
105105
security_group:bool = True
106+
107+
class IaCTemplateGenerationCloudFront(BaseModel):
108+
109+
distribution:bool = True
110+
origin_access_identity:bool = True
111+
origin_access_control:bool = False
112+
monitoring_subscription:bool = False
113+
vpc_origin:bool = False

app/routes/terraform.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
IaCTemplateGenerationArgoCD,
1616
IaCTemplateGenerationELB,
1717
IaCTemplateGenerationEFS,
18-
IaCTemplateGenerationALB
18+
IaCTemplateGenerationALB,
19+
IaCTemplateGenerationCloudFront
1920
)
2021

2122
from fastapi import Response
@@ -32,6 +33,7 @@
3233
from app.template_generators.terraform.aws.ELB import (IaC_template_generator_elb)
3334
from app.template_generators.terraform.aws.EFS import (IaC_template_generator_efs)
3435
from app.template_generators.terraform.aws.ALB import (IaC_template_generator_alb)
36+
from app.template_generators.terraform.aws.CloudFront import (IaC_template_generator_cloudfront)
3537
from app.template_generators.terraform.Installation.main import (select_install)
3638
import os
3739

@@ -155,3 +157,15 @@ async def IaC_template_generation_aws_alb(request:IaCTemplateGenerationALB) -> O
155157

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

160+
161+
@app.post("/api/IaC-template/aws/cloudfront")
162+
async def IaC_template_generation_aws_cloudfront(request:IaCTemplateGenerationCloudFront) -> Output:
163+
164+
dir = 'app/media/terraform.tfvars'
165+
166+
file_response = IaC_template_generator_cloudfront(request)
167+
with open(dir,'w')as f:
168+
f.write(file_response)
169+
170+
return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars")
171+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def IaC_template_generator_cloudfront(input) -> str:
2+
3+
aws_cloudfront_create_distribution = 'true' if input.distribution else 'false'
4+
aws_cloudfront_create_origin_access_identity = 'true' if input.origin_access_identity else 'false'
5+
aws_cloudfront_create_origin_access_control = 'true' if input.origin_access_control else 'false'
6+
aws_cloudfront_create_monitoring_subscription = 'true' if input.monitoring_subscription else 'false'
7+
aws_cloudfront_create_vpc_origin = 'true' if input.vpc_origin else 'false'
8+
9+
tfvars_file = f"""create_distribution = {aws_cloudfront_create_distribution}
10+
create_origin_access_identity = {aws_cloudfront_create_origin_access_identity}
11+
create_origin_access_control = {aws_cloudfront_create_origin_access_control}
12+
create_monitoring_subscription = {aws_cloudfront_create_monitoring_subscription}
13+
create_vpc_origin = {aws_cloudfront_create_vpc_origin}
14+
"""
15+
return tfvars_file

0 commit comments

Comments
 (0)