Skip to content
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
15 changes: 15 additions & 0 deletions app/media/MyTerraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

provider "aws" {
region = "us-east-1"
}

module "ec2" {
key_pair_create = var.key_pair_create
key_pair_name = var.key_pair_name
security_group_create = var.security_group_create
security_group_name = var.security_group_name
security_group_ingress_rules = var.security_group_ingress_rules
security_group_egress_rule = var.security_group_egress_rule
instance_create = var.instance_create
instance_type = var.instance_type
}
57 changes: 57 additions & 0 deletions app/media/MyTerraform/modules/ec2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

data "aws_ami" "linux" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["al2023-ami-2023*kernel-6.1-x86_64"]
}

filter {
name = "root-device-type"
values = ["ebs"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}
}

resource "aws_key_pair" "key_pair" {
count = var.key_pair_create ? 1 : 0
key_name = var.key_pair_name
public_key = file("${path.module}/terraform.pub")
}

resource "aws_security_group" "security_group" {
count = var.security_group_create ? 1 : 0
name = var.security_group_name

dynamic "ingress" {
for_each = var.security_group_ingress_rules
content {
description = ingress.value["description"]
from_port = ingress.value["from_port"]
to_port = ingress.value["to_port"]
protocol = ingress.value["protocol"]
cidr_blocks = ingress.value["cidr_blocks"]
}
}

egress {
from_port = var.security_group_egress_rule["from_port"]
to_port = var.security_group_egress_rule["to_port"]
protocol = var.security_group_egress_rule["protocol"]
cidr_blocks = var.security_group_egress_rule["cidr_blocks"]
}
}

resource "aws_instance" "instance" {
count = var.instance_create ? 1 : 0
ami = data.aws_ami.linux.id
instance_type = var.instance_type
key_name = var.key_pair_create ? aws_key_pair.key_pair[0].key_name : null
vpc_security_group_ids = var.security_group_create ? [aws_security_group.security_group[0].id] : null
}
Empty file.
31 changes: 31 additions & 0 deletions app/media/MyTerraform/modules/ec2/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

key_pair_create = true
key_pair_name = "ec2"

security_group_create = true
security_group_name = "my_rules"
security_group_ingress_rules = {
ssh_rule = {
description = "SSH Ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
},
http_rule = {
description = "HTTP Ingress"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
security_group_egress_rule = {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

instance_create = true
instance_type = "t2.micro"
51 changes: 51 additions & 0 deletions app/media/MyTerraform/modules/ec2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

variable "key_pair_create" {
description = "Create Key Pair"
type = bool
}

variable "key_pair_name" {
description = "Key Pair Name"
type = string
}

variable "security_group_create" {
description = "Create Security Group"
type = bool
}

variable "security_group_name" {
description = "Security Group Name"
type = string
}

variable "security_group_ingress_rules" {
description = "Security Group Ingress Rules"
type = map(object({
description = string
from_port = number
to_port = number
protocol = string
cidr_blocks = list(string)
}))
}

variable "security_group_egress_rule" {
description = "Security Group Egress Rule"
type = object({
from_port = number
to_port = number
protocol = string
cidr_blocks = list(string)
})
}

variable "instance_create" {
description = "Create EC2 Instance"
type = bool
}

variable "instance_type" {
description = "EC2 Instance Type"
type = string
}
11 changes: 11 additions & 0 deletions app/media/MyTerraform/modules/ec2/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.20"
}
}
}
31 changes: 31 additions & 0 deletions app/media/MyTerraform/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

key_pair_create = true
key_pair_name = "ec2"

security_group_create = true
security_group_name = "my_rules"
security_group_ingress_rules = {
ssh_rule = {
description = "SSH Ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
},
http_rule = {
description = "HTTP Ingress"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
security_group_egress_rule = {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

instance_create = true
instance_type = "t2.micro"
51 changes: 51 additions & 0 deletions app/media/MyTerraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

variable "key_pair_create" {
description = "Create Key Pair"
type = bool
}

variable "key_pair_name" {
description = "Key Pair Name"
type = string
}

variable "security_group_create" {
description = "Create Security Group"
type = bool
}

variable "security_group_name" {
description = "Security Group Name"
type = string
}

variable "security_group_ingress_rules" {
description = "Security Group Ingress Rules"
type = map(object({
description = string
from_port = number
to_port = number
protocol = string
cidr_blocks = list(string)
}))
}

variable "security_group_egress_rule" {
description = "Security Group Egress Rule"
type = object({
from_port = number
to_port = number
protocol = string
cidr_blocks = list(string)
})
}

variable "instance_create" {
description = "Create EC2 Instance"
type = bool
}

variable "instance_type" {
description = "EC2 Instance Type"
type = string
}
11 changes: 11 additions & 0 deletions app/media/MyTerraform/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.20"
}
}
}
8 changes: 7 additions & 1 deletion app/models/terraform_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ class IaCTemplateGenerationS3(BaseModel):

class IaCTemplateGenerationIAM(BaseModel):
iam_user:bool = True
iam_group:bool = True
iam_group:bool = True

class IaCTemplateGenerationArgoCD(BaseModel):
argocd_application:bool = True
argocd_project:bool = True
argocd_repository:bool = True
argocd_cluster:bool = True
11 changes: 11 additions & 0 deletions app/routes/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
IaCTemplateGenerationEC2,
IaCTemplateGenerationS3,
IaCTemplateGenerationIAM,
IaCTemplateGenerationArgoCD
)

from fastapi import Response
Expand All @@ -23,6 +24,7 @@
from app.template_generators.terraform.aws.ec2 import (IaC_template_generator_ec2)
from app.template_generators.terraform.aws.IAM import (IaC_template_generator_iam)
from app.template_generators.terraform.aws.s3 import (IaC_template_generator_s3)
from app.template_generators.terraform.argocd import (IaC_template_generator_argocd)
import os

@app.post("/IaC-basic/")
Expand Down Expand Up @@ -92,3 +94,12 @@ async def IaC_template_generation_aws_iam(request:IaCTemplateGenerationIAM) -> O
return Output(output='output')


@app.post("/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')
2 changes: 2 additions & 0 deletions app/template_generators/terraform/argocd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def IaC_template_generator_argocd(input) -> str:
pass
Loading