Skip to content

Commit f010a12

Browse files
committed
added EBS Volume module
1 parent c63c197 commit f010a12

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed

terraform-aws-ebs/ebs_volume.tf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "aws_ebs_volume" "ebs_volume" {
2+
availability_zone = "us-east-1a"
3+
size = 20
4+
type = "gp2"
5+
6+
tags = {
7+
Name = "ebs-volume-terraform-demo"
8+
}
9+
}
10+
11+
resource "aws_volume_attachment" "ebc_volume_attachment" {
12+
device_name = "/dev/xvdh"
13+
volume_id = aws_ebs_volume.ebs_volume.id
14+
instance_id = aws_instance.ebs_instance_example.id
15+
}

terraform-aws-ebs/instance.tf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
resource "aws_instance" "ebs_instance_example" {
6+
ami = lookup(var.ami_id, var.region)
7+
instance_type = var.instance_type
8+
subnet_id = aws_subnet.public_1.id
9+
10+
# Security group assign to instance
11+
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
12+
13+
# key name
14+
key_name = var.key_name
15+
16+
tags = {
17+
Name = "Ec2-with-VPC"
18+
}
19+
}

terraform-aws-ebs/security_group.tf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
resource "aws_security_group" "allow_ssh" {
2+
name = "allow_SSH"
3+
description = "Allow SSH inbound traffic"
4+
vpc_id = aws_vpc.vpc_demo.id
5+
6+
ingress {
7+
# SSH Port 22 allowed from any IP
8+
from_port = 22
9+
to_port = 22
10+
protocol = "tcp"
11+
cidr_blocks = ["0.0.0.0/0"]
12+
}
13+
14+
egress {
15+
from_port = 0
16+
to_port = 0
17+
protocol = "-1"
18+
cidr_blocks = ["0.0.0.0/0"]
19+
}
20+
}

terraform-aws-ebs/variables.tf

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
variable "region" {
2+
type = "string"
3+
default = "us-east-1"
4+
}
5+
variable "ami_id" {
6+
type = "map"
7+
default = {
8+
us-east-1 = "ami-035b3c7efe6d061d5"
9+
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
10+
eu-central-1 = "ami-9787h5h6nsn75gd33"
11+
}
12+
}
13+
variable "instance_type" {
14+
type = "string"
15+
default = "t2.micro"
16+
}
17+
variable "key_name" {
18+
type = "string"
19+
default = "ec2-demo"
20+
}
21+
22+
variable "cidr" {
23+
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
24+
type = string
25+
default = "10.0.0.0/16"
26+
}
27+
variable "instance_tenancy" {
28+
description = "A tenancy option for instances launched into the VPC"
29+
type = string
30+
default = "default"
31+
}
32+
33+
variable "enable_dns_hostnames" {
34+
description = "Should be true to enable DNS hostnames in the VPC"
35+
type = bool
36+
default = true
37+
}
38+
39+
variable "enable_dns_support" {
40+
description = "Should be true to enable DNS support in the VPC"
41+
type = bool
42+
default = true
43+
}
44+
45+
variable "enable_classiclink" {
46+
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
47+
type = bool
48+
default = false
49+
}
50+
51+
variable "tags" {
52+
description = "A map of tags to add to all resources"
53+
type = string
54+
default = "Vpc-custom-demo"
55+
}

terraform-aws-ebs/vpc.tf

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
resource "aws_vpc" "vpc_demo" {
2+
cidr_block = var.cidr
3+
instance_tenancy = var.instance_tenancy
4+
enable_dns_hostnames = var.enable_dns_hostnames
5+
enable_dns_support = var.enable_dns_support
6+
enable_classiclink = var.enable_classiclink
7+
8+
tags = {
9+
Name = var.tags
10+
}
11+
}
12+
13+
resource "aws_internet_gateway" "gw" {
14+
vpc_id = aws_vpc.vpc_demo.id
15+
16+
tags = {
17+
Name = "internet-gateway-demo"
18+
}
19+
}
20+
21+
resource "aws_subnet" "public_1" {
22+
availability_zone = "us-east-1a"
23+
vpc_id = aws_vpc.vpc_demo.id
24+
map_public_ip_on_launch = true
25+
cidr_block = "10.0.1.0/24"
26+
27+
tags = {
28+
Name = "public_1-demo"
29+
}
30+
}
31+
32+
resource "aws_route_table" "route-public" {
33+
vpc_id = aws_vpc.vpc_demo.id
34+
35+
route {
36+
cidr_block = "10.0.0.0/0"
37+
gateway_id = aws_internet_gateway.gw.id
38+
}
39+
40+
tags = {
41+
Name = "public-route-table-demo"
42+
}
43+
}
44+
45+
resource "aws_route_table_association" "public_1" {
46+
subnet_id = aws_subnet.public_1.id
47+
route_table_id = aws_route_table.route-public.id
48+
}

0 commit comments

Comments
 (0)