Skip to content
Closed
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
48 changes: 48 additions & 0 deletions AWS Module/EC2 Instance/Variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
variable "access_key" {
description = "Access key to AWS console"
type = Secret

}
variable "secret_key" {
description = "Secret key to AWS console"
type = secret_key
}

variable "region" {
type = string
}

variable "instance_name" {
description = "Value of the Name tag for the EC2 instance"
type = string
}

variable "instance_name" {
description = "Name of the instance to be created"
type = string
}

variable "instance_type" {
description = "type of instance "
default = "t2.micro"
}

variable "subnet_id" {
description = "The VPC subnet the instance(s) will be created in"
type = string
}

variable "ami_id" {
description = "The AMI to use"
type = string
}

variable "number_of_instances" {
description = "number of instances to be created"
default = 1
}


variable "ami_key_pair_name" {
description = "name of your keypair"
}
19 changes: 19 additions & 0 deletions AWS Module/EC2 Instance/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
Comment on lines +1 to +5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}

@RashRAJ we can take this out as it would be defined by the module user e.g.
#2


resource "aws_instance" "ec2_instance" {
ami = "${var.ami_id}"
count = "${var.number_of_instances}"
subnet_id = "${var.subnet_id}"
instance_type = "${var.instance_type}"
key_name = "${var.ami_key_pair_name}"
security_groups = [ "value" ]


tags = {
Name = "${var.instance_name}"
}
}
16 changes: 16 additions & 0 deletions AWS Module/EC2 Instance/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
output "Private_ip" {
value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2instance.*.private_ip)
}

output "Public_ip" {
value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2instance.*.private_ip)
}


output "public_dns" {
value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_eip.eip.*.public_dns)
}

output "private_dns" {
value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_instance.ec2instance.*.private_dns)
}
2 changes: 2 additions & 0 deletions AWS Module/EC2 Instance/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
access_key = "Access Key of IAM User"
secret_key = "Secret Key of IAM User"
52 changes: 52 additions & 0 deletions AWS Module/Load Balancer/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
resource "aws_lb" "alb" {
name = "${var.alb_name}"
internal = true
load_balancer_type = "applcation"
security_groups = ["value"]
subnets = [ "value" ]
enable_http2 = false
enable_deletion_protection = false

tags = {
name = "${var.alb_name}"
}
}


resource "aws_lb_target_group" "target_group" {
name = "${var.tg_name}"
port = 80
protocol = "HTTP"
target_type = "instance"
vpc_id = []

health_check {
path = "/"
protocol = "HTTP"
matcher = "200"
interval = 15
healthy_threshold = 3
timeout = 3
unhealthy_threshold = 3
}

}

resource "aws_lb_target_group_attachment" "tg_atch" {
target_group_arn = aws_lb_target_group.target_group.arn
target_id = aws_lb_target_group.target_group.id
port = 80
}

resource "aws_lb_listener" "front_end" {
load_balancer_arn = aws_lb.alb.arn
port = "80"
protocol = "HTTP"

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.target_group.arn
}

}

3 changes: 3 additions & 0 deletions AWS Module/Load Balancer/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "alb_id" {
value = aws_lb.lb.dns_name
}
5 changes: 5 additions & 0 deletions AWS Module/Load Balancer/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "alb_name" {
description ="name of the application load balancer"
type = string
}

Empty file added AWS Module/Route 53/main.tf
Empty file.
Empty file added AWS Module/Route 53/output.tf
Empty file.
Empty file added AWS Module/Route 53/variable.tf
Empty file.
29 changes: 29 additions & 0 deletions AWS Module/Security Group/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
resource "aws_security_group" "security_group" {

name = "${var.security_group}"
vpc_id = [value]

ingress = [ {
cidr_blocks = [ "value" ]
description = "value"
from_port = 1
ipv6_cidr_blocks = [ "value" ]
prefix_list_ids = [ "value" ]
protocol = "value"
security_groups = ["value"]
self = false
to_port = 1
} ]

egress = [ {
cidr_blocks = [ "value" ]
description = "value"
from_port = 1
ipv6_cidr_blocks = [ "value" ]
prefix_list_ids = [ "value" ]
protocol = "value"
security_groups = [ "value" ]
self = false
to_port = 1
} ]
}
3 changes: 3 additions & 0 deletions AWS Module/Security Group/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "security_group" {
value = aws_security_group.security_group.id
}
4 changes: 4 additions & 0 deletions AWS Module/Security Group/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "security_group" {
description = "name of the sequrity group"
type = string
}
Empty file added AWS Module/VPC/main.tf
Empty file.
Empty file added AWS Module/VPC/output.tf
Empty file.
Empty file added AWS Module/VPC/variable.tf
Empty file.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Terraform
# Terraform
28 changes: 28 additions & 0 deletions aws_module/ec2_instance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Ignore .terraform directory
.terraform/

# Ignore any generated files
*.tfstate
*.tfstate.backup
*.tfvars

# Ignore any override files
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Ignore any local files
terraform.tfstate
terraform.tfstate.backup

# Ignore any plan files
*.tfplan

# Ignore any log files
*.log
*.out
*.aux

# Ignore any .DS_Store files (macOS specific)
.DS_Store
37 changes: 37 additions & 0 deletions aws_module/ec2_instance/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}

required_version = ">= 1.2.0"
}

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



resource "aws_instance" "ec2_instance" {
ami = var.ami_id
subnet_id = var.subnet_id
instance_type = var.instance_type

#key_name = var.ami_key_pair_name
#security_groups = aws_security_group.security_group.id
#count = var.number_of_instances


tags = {
Name = "${var.instance_name}"
}
}


resource "aws_eip" "elastic_ip" {
instance = aws_instance.ec2_instance.id
vpc = true
}
17 changes: 17 additions & 0 deletions aws_module/ec2_instance/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
output "Private_ip" {
value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_ip)
}

output "Public_ip" {
value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_ip)
}


#output "public_dns" {
# value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_eip.eip.*.public_dns)
#}


output "private_dns" {
value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_dns)
}
2 changes: 2 additions & 0 deletions aws_module/ec2_instance/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
access_key = "Access Key of IAM User"
secret_key = "Secret Key of IAM User"
38 changes: 38 additions & 0 deletions aws_module/ec2_instance/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

variable "region" {
type = string
default = "us-east-1"
}

variable "instance_name" {
description = "Name of the instance to be created"
type = string
default = "hostapace_ec2"
}

variable "instance_type" {
description = "type of instance "
default = "t2.micro"
}

variable "subnet_id" {
description = "The VPC subnet the instance(s) will be created in"
type = string
}

variable "ami_id" {
description = "The AMI to use"
type = string
default = "ami-006dcf34c09e50022"
}

variable "number_of_instances" {
description = "number of instances to be created"
default = 1
}


variable "ami_key_pair_name" {
description = "name of your keypair"
default = "./mykeypair.pem"
}
52 changes: 52 additions & 0 deletions aws_module/load_balancer/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
resource "aws_lb" "alb" {
name = "${var.alb_name}"
internal = true
load_balancer_type = "applcation"
security_groups = aws_security_group.security_group.id
subnets = [ "value" ]
enable_http2 = false
enable_deletion_protection = false

tags = {
name = "${var.alb_name}"
}
}


resource "aws_lb_target_group" "target_group" {
name = "${var.tg_name}"
port = 80
protocol = "HTTP"
target_type = "instance"
vpc_id = []

health_check {
path = "/"
protocol = "HTTP"
matcher = "200"
interval = 15
healthy_threshold = 3
timeout = 3
unhealthy_threshold = 3
}

}

resource "aws_lb_target_group_attachment" "tg_atch" {
target_group_arn = aws_lb_target_group.target_group.arn
target_id = aws_lb_target_group.target_group.id
port = 80
}

resource "aws_lb_listener" "front_end" {
load_balancer_arn = aws_lb.alb.arn
port = "80"
protocol = "HTTP"

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.target_group.arn
}

}

3 changes: 3 additions & 0 deletions aws_module/load_balancer/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "alb_id" {
value = aws_lb.lb.dns_name
}
5 changes: 5 additions & 0 deletions aws_module/load_balancer/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "alb_name" {
description ="name of the application load balancer"
type = string
}

Empty file added aws_module/route53/main.tf
Empty file.
Empty file added aws_module/route53/output.tf
Empty file.
Empty file added aws_module/route53/variable.tf
Empty file.
Loading