Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform-templates): implementing aws-cloudfront route #165

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/media/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
alb_create = true
create_security_group = true
create_distribution = true
create_origin_access_identity = true
create_origin_access_control = false
create_monitoring_subscription = false
create_vpc_origin = false
8 changes: 8 additions & 0 deletions app/models/terraform_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ class IaCTemplateGenerationALB(BaseModel):

alb_resources:bool = True
security_group:bool = True

class IaCTemplateGenerationCloudFront(BaseModel):

distribution:bool = True
origin_access_identity:bool = True
origin_access_control:bool = False
monitoring_subscription:bool = False
vpc_origin:bool = False
16 changes: 15 additions & 1 deletion app/routes/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
IaCTemplateGenerationArgoCD,
IaCTemplateGenerationELB,
IaCTemplateGenerationEFS,
IaCTemplateGenerationALB
IaCTemplateGenerationALB,
IaCTemplateGenerationCloudFront
)

from fastapi import Response
Expand All @@ -32,6 +33,7 @@
from app.template_generators.terraform.aws.ELB import (IaC_template_generator_elb)
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.Installation.main import (select_install)
import os

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

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


@app.post("/api/IaC-template/aws/cloudfront")
async def IaC_template_generation_aws_cloudfront(request:IaCTemplateGenerationCloudFront) -> Output:

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_cloudfront(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/CloudFront.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def IaC_template_generator_cloudfront(input) -> str:

aws_cloudfront_create_distribution = 'true' if input.distribution else 'false'
aws_cloudfront_create_origin_access_identity = 'true' if input.origin_access_identity else 'false'
aws_cloudfront_create_origin_access_control = 'true' if input.origin_access_control else 'false'
aws_cloudfront_create_monitoring_subscription = 'true' if input.monitoring_subscription else 'false'
aws_cloudfront_create_vpc_origin = 'true' if input.vpc_origin else 'false'

tfvars_file = f"""create_distribution = {aws_cloudfront_create_distribution}
create_origin_access_identity = {aws_cloudfront_create_origin_access_identity}
create_origin_access_control = {aws_cloudfront_create_origin_access_control}
create_monitoring_subscription = {aws_cloudfront_create_monitoring_subscription}
create_vpc_origin = {aws_cloudfront_create_vpc_origin}
"""
return tfvars_file
Loading