Skip to content

Commit 6a66477

Browse files
authored
Merge pull request #74 from abolfazl8131/master
feat(argocd): add argocd to terraform
2 parents ea8637d + 225be4f commit 6a66477

12 files changed

Lines changed: 278 additions & 1 deletion

File tree

app/media/MyTerraform/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
provider "aws" {
3+
region = "us-east-1"
4+
}
5+
6+
module "ec2" {
7+
key_pair_create = var.key_pair_create
8+
key_pair_name = var.key_pair_name
9+
security_group_create = var.security_group_create
10+
security_group_name = var.security_group_name
11+
security_group_ingress_rules = var.security_group_ingress_rules
12+
security_group_egress_rule = var.security_group_egress_rule
13+
instance_create = var.instance_create
14+
instance_type = var.instance_type
15+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
data "aws_ami" "linux" {
3+
most_recent = true
4+
owners = ["amazon"]
5+
6+
filter {
7+
name = "name"
8+
values = ["al2023-ami-2023*kernel-6.1-x86_64"]
9+
}
10+
11+
filter {
12+
name = "root-device-type"
13+
values = ["ebs"]
14+
}
15+
16+
filter {
17+
name = "virtualization-type"
18+
values = ["hvm"]
19+
}
20+
}
21+
22+
resource "aws_key_pair" "key_pair" {
23+
count = var.key_pair_create ? 1 : 0
24+
key_name = var.key_pair_name
25+
public_key = file("${path.module}/terraform.pub")
26+
}
27+
28+
resource "aws_security_group" "security_group" {
29+
count = var.security_group_create ? 1 : 0
30+
name = var.security_group_name
31+
32+
dynamic "ingress" {
33+
for_each = var.security_group_ingress_rules
34+
content {
35+
description = ingress.value["description"]
36+
from_port = ingress.value["from_port"]
37+
to_port = ingress.value["to_port"]
38+
protocol = ingress.value["protocol"]
39+
cidr_blocks = ingress.value["cidr_blocks"]
40+
}
41+
}
42+
43+
egress {
44+
from_port = var.security_group_egress_rule["from_port"]
45+
to_port = var.security_group_egress_rule["to_port"]
46+
protocol = var.security_group_egress_rule["protocol"]
47+
cidr_blocks = var.security_group_egress_rule["cidr_blocks"]
48+
}
49+
}
50+
51+
resource "aws_instance" "instance" {
52+
count = var.instance_create ? 1 : 0
53+
ami = data.aws_ami.linux.id
54+
instance_type = var.instance_type
55+
key_name = var.key_pair_create ? aws_key_pair.key_pair[0].key_name : null
56+
vpc_security_group_ids = var.security_group_create ? [aws_security_group.security_group[0].id] : null
57+
}

app/media/MyTerraform/modules/ec2/terraform.pub

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
key_pair_create = true
3+
key_pair_name = "ec2"
4+
5+
security_group_create = true
6+
security_group_name = "my_rules"
7+
security_group_ingress_rules = {
8+
ssh_rule = {
9+
description = "SSH Ingress"
10+
from_port = 22
11+
to_port = 22
12+
protocol = "tcp"
13+
cidr_blocks = ["0.0.0.0/0"]
14+
},
15+
http_rule = {
16+
description = "HTTP Ingress"
17+
from_port = 80
18+
to_port = 80
19+
protocol = "tcp"
20+
cidr_blocks = ["0.0.0.0/0"]
21+
}
22+
}
23+
security_group_egress_rule = {
24+
from_port = 0
25+
to_port = 0
26+
protocol = "-1"
27+
cidr_blocks = ["0.0.0.0/0"]
28+
}
29+
30+
instance_create = true
31+
instance_type = "t2.micro"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
variable "key_pair_create" {
3+
description = "Create Key Pair"
4+
type = bool
5+
}
6+
7+
variable "key_pair_name" {
8+
description = "Key Pair Name"
9+
type = string
10+
}
11+
12+
variable "security_group_create" {
13+
description = "Create Security Group"
14+
type = bool
15+
}
16+
17+
variable "security_group_name" {
18+
description = "Security Group Name"
19+
type = string
20+
}
21+
22+
variable "security_group_ingress_rules" {
23+
description = "Security Group Ingress Rules"
24+
type = map(object({
25+
description = string
26+
from_port = number
27+
to_port = number
28+
protocol = string
29+
cidr_blocks = list(string)
30+
}))
31+
}
32+
33+
variable "security_group_egress_rule" {
34+
description = "Security Group Egress Rule"
35+
type = object({
36+
from_port = number
37+
to_port = number
38+
protocol = string
39+
cidr_blocks = list(string)
40+
})
41+
}
42+
43+
variable "instance_create" {
44+
description = "Create EC2 Instance"
45+
type = bool
46+
}
47+
48+
variable "instance_type" {
49+
description = "EC2 Instance Type"
50+
type = string
51+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
terraform {
3+
required_version = ">= 1.0"
4+
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 5.20"
9+
}
10+
}
11+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
key_pair_create = true
3+
key_pair_name = "ec2"
4+
5+
security_group_create = true
6+
security_group_name = "my_rules"
7+
security_group_ingress_rules = {
8+
ssh_rule = {
9+
description = "SSH Ingress"
10+
from_port = 22
11+
to_port = 22
12+
protocol = "tcp"
13+
cidr_blocks = ["0.0.0.0/0"]
14+
},
15+
http_rule = {
16+
description = "HTTP Ingress"
17+
from_port = 80
18+
to_port = 80
19+
protocol = "tcp"
20+
cidr_blocks = ["0.0.0.0/0"]
21+
}
22+
}
23+
security_group_egress_rule = {
24+
from_port = 0
25+
to_port = 0
26+
protocol = "-1"
27+
cidr_blocks = ["0.0.0.0/0"]
28+
}
29+
30+
instance_create = true
31+
instance_type = "t2.micro"

app/media/MyTerraform/variables.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
variable "key_pair_create" {
3+
description = "Create Key Pair"
4+
type = bool
5+
}
6+
7+
variable "key_pair_name" {
8+
description = "Key Pair Name"
9+
type = string
10+
}
11+
12+
variable "security_group_create" {
13+
description = "Create Security Group"
14+
type = bool
15+
}
16+
17+
variable "security_group_name" {
18+
description = "Security Group Name"
19+
type = string
20+
}
21+
22+
variable "security_group_ingress_rules" {
23+
description = "Security Group Ingress Rules"
24+
type = map(object({
25+
description = string
26+
from_port = number
27+
to_port = number
28+
protocol = string
29+
cidr_blocks = list(string)
30+
}))
31+
}
32+
33+
variable "security_group_egress_rule" {
34+
description = "Security Group Egress Rule"
35+
type = object({
36+
from_port = number
37+
to_port = number
38+
protocol = string
39+
cidr_blocks = list(string)
40+
})
41+
}
42+
43+
variable "instance_create" {
44+
description = "Create EC2 Instance"
45+
type = bool
46+
}
47+
48+
variable "instance_type" {
49+
description = "EC2 Instance Type"
50+
type = string
51+
}

app/media/MyTerraform/versions.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
terraform {
3+
required_version = ">= 1.0"
4+
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 5.20"
9+
}
10+
}
11+
}

app/models/terraform_models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,10 @@ class IaCTemplateGenerationS3(BaseModel):
7979

8080
class IaCTemplateGenerationIAM(BaseModel):
8181
iam_user:bool = True
82-
iam_group:bool = True
82+
iam_group:bool = True
83+
84+
class IaCTemplateGenerationArgoCD(BaseModel):
85+
argocd_application:bool = True
86+
argocd_project:bool = True
87+
argocd_repository:bool = True
88+
argocd_cluster:bool = True

0 commit comments

Comments
 (0)