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

fix(terraform refactore): re-design terraform endpoints #158

Merged
merged 1 commit into from
Dec 22, 2024
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
115 changes: 14 additions & 101 deletions app/media/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,103 +1,16 @@

# Grafana Connection Variables
grafana_connection = {
"url" = "http://localhost:8080",
"auth" = ""
}



# Grafana_Contact_Point Variables
create_contact_point = true
contact_point_name = "My Contact Point"
use_email = false
use_slack = true
email_contact_point = {
addresses = ["one@company.org", "two@company.org"]
message = "{ len .Alerts.Firing } firing."
subject = "{{ template \"default.title\" .}}"
single_email = true
disable_resolve_message = false
}

slack_contact_point = {
url = "https://hooks.slack.com/<YOUR_SLACK_WEBHOOK_URL>"
text = <<EOT
{{ len .Alerts.Firing }} alerts are firing

Alert summaries:
{{ range .Alerts.Firing }}
{{ template "Alert Instance Template" . }}
{{ end }}
EOT
}


# Use { template "Alert Instance Template" . } or any other template if you plan # to create one. Otherwise, remove it from the text section of Slack in the above example


# Grafana_Message_Template Variables
create_message_template = true
message_template_name = "Alert Instance Template"
message_template_content = <<EOT
{{ define "Alert Instance Template" }}
Firing: {{ .Labels.alertname }}
Silence: {{ .SilenceURL }}
{{ end }}
EOT



# Grafana_Mute_Timing Variables
create_mute_timing = true
mute_timing = {
name = "My Mute Timing"
start = "04:56"
end = "04:57"
weekdays = ["monday", "tuesday:thursday"]
days_of_month = ["1:7", "-1"]
months = ["1:3", "december"]
years = []
}




# Grafana_Notification_Policy Variables
create_notification_policy = true
notification_policy_config = {
group_by = ["..."]
group_wait = "45s"
group_interval = "6m"
repeat_interval = "3h"
}


policies = []
/* policies = [
{
matchers = [
{ label = "mylabel", match = "=", value = "myvalue" },
{ label = "alertname", match = "=", value = "CPU Usage" },
{ label = "Name", match = "=~", value = "host.*|host-b.*" }
]
contact_point = "a_contact_point_1"
continue = true
mute_timings = ["mute_timing_1"]
group_by = ["group1_sub"]
},
iam_create_user = true
iam_users = [
{
name = "devopshobbies"
path = "/"
}
]

iam_create_group = true
iam_groups = [
{
matchers = [
{ label = "sublabel", match = "=", value = "subvalue" }
]
contact_point = "a_contact_point_1"
continue = false
mute_timings = ["mute_timing_2"]
group_by = ["group2_sub"]
}


] */

name = "developers"
path = "/"
}

]
1 change: 1 addition & 0 deletions app/routes/grafana_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def zip_folder(folder_path: str, output_zip_path: str):
file_path = os.path.join(root, file)
# Add file to the zip file
zip_file.write(file_path, os.path.relpath(file_path, folder_path))

@app.post("/api/grafana/terraform")
async def grafana_terraform_template_route(request:GrafanaTerraform) -> Output:

Expand Down
110 changes: 61 additions & 49 deletions app/routes/terraform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from app.app_instance import app
from app.gpt_services import gpt_service
from fastapi.responses import FileResponse
from app.services import (

edit_directory_generator,execute_pythonfile)
Expand Down Expand Up @@ -58,74 +59,85 @@ async def IaC_install_generation(request:IaCInstallationInput) -> Output:

@app.post("/api/IaC-template/docker")
async def IaC_template_generation_docker(request:IaCTemplateGenerationDocker) -> Output:
if os.environ.get("TEST"):
return Output(output='output (nothing special)')
generated_prompt = IaC_template_generator_docker(request)
output = gpt_service(generated_prompt)
edit_directory_generator("terraform_generator",output)
execute_pythonfile("MyTerraform","terraform_generator")
return Output(output='output')

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_docker(request)
with open(dir,'w')as f:
f.write(file_response)

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

@app.post("/api/IaC-template/aws/ec2")
async def IaC_template_generation_aws_ec2(request:IaCTemplateGenerationEC2) -> Output:
if os.environ.get("TEST"):
return Output(output='output (nothing special)')

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_ec2(request)
with open(dir,'w')as f:
f.write(file_response)

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

generated_prompt = IaC_template_generator_ec2(request)
output = gpt_service(generated_prompt)
edit_directory_generator("terraform_generator",output)
execute_pythonfile("MyTerraform","terraform_generator")
return Output(output='output')

@app.post("/api/IaC-template/aws/s3")
async def IaC_template_generation_aws_s3(request:IaCTemplateGenerationS3) -> Output:
if os.environ.get("TEST"):
return Output(output='output (nothing special)')
generated_prompt = IaC_template_generator_s3(request)
output = gpt_service(generated_prompt)
edit_directory_generator("terraform_generator",output)
execute_pythonfile("MyTerraform","terraform_generator")
return Output(output='output')

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_s3(request)
with open(dir,'w')as f:
f.write(file_response)

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


@app.post("/api/IaC-template/aws/iam")
async def IaC_template_generation_aws_iam(request:IaCTemplateGenerationIAM) -> Output:
if os.environ.get("TEST"):
return Output(output='output (nothing special)')
generated_prompt = IaC_template_generator_iam(request)
output = gpt_service(generated_prompt)
edit_directory_generator("terraform_generator",output)
execute_pythonfile("MyTerraform","terraform_generator")
return Output(output='output')

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_iam(request)
with open(dir,'w')as f:
f.write(file_response)

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



@app.post("/api/IaC-template/argocd")
async def IaC_template_generation_argocd(request:IaCTemplateGenerationArgoCD) -> Output:
if os.environ.get("TEST"):
return Output(output='output (nothing special)')
generated_prompt = IaC_template_generator_argocd(request)
output = gpt_service(generated_prompt)
edit_directory_generator("terraform_generator",output)
execute_pythonfile("MyTerraform","terraform_generator")
return Output(output='output')

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_argocd(request)
with open(dir,'w')as f:
f.write(file_response)

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



@app.post("/api/IaC-template/aws/elb")
async def IaC_template_generation_aws_elb(request:IaCTemplateGenerationELB) -> Output:
if os.environ.get("TEST"):
return Output(output='output (nothing special)')
generated_prompt = IaC_template_generator_elb(request)
output = gpt_service(generated_prompt)
edit_directory_generator("terraform_generator",output)
execute_pythonfile("MyTerraform","terraform_generator")
return Output(output='output')

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_elb(request)
with open(dir,'w')as f:
f.write(file_response)

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


@app.post("/api/IaC-template/aws/efs")
async def IaC_template_generation_aws_efs(request:IaCTemplateGenerationEFS) -> Output:
if os.environ.get("TEST"):
return Output(output='output (nothing special)')
generated_prompt = IaC_template_generator_efs(request)
output = gpt_service(generated_prompt)
edit_directory_generator("terraform_generator",output)
execute_pythonfile("MyTerraform","terraform_generator")
return Output(output='output')

dir = 'app/media/terraform.tfvars'

file_response = IaC_template_generator_efs(request)
with open(dir,'w')as f:
f.write(file_response)

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

Loading
Loading