Skip to content

Commit

Permalink
added EBS Volume module
Browse files Browse the repository at this point in the history
  • Loading branch information
easyawslearn committed Sep 25, 2019
1 parent c63c197 commit f010a12
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
15 changes: 15 additions & 0 deletions terraform-aws-ebs/ebs_volume.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "aws_ebs_volume" "ebs_volume" {
availability_zone = "us-east-1a"
size = 20
type = "gp2"

tags = {
Name = "ebs-volume-terraform-demo"
}
}

resource "aws_volume_attachment" "ebc_volume_attachment" {
device_name = "/dev/xvdh"
volume_id = aws_ebs_volume.ebs_volume.id
instance_id = aws_instance.ebs_instance_example.id
}
19 changes: 19 additions & 0 deletions terraform-aws-ebs/instance.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
provider "aws" {
region = var.region
}

resource "aws_instance" "ebs_instance_example" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
subnet_id = aws_subnet.public_1.id

# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh.id]

# key name
key_name = var.key_name

tags = {
Name = "Ec2-with-VPC"
}
}
20 changes: 20 additions & 0 deletions terraform-aws-ebs/security_group.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "aws_security_group" "allow_ssh" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id

ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
55 changes: 55 additions & 0 deletions terraform-aws-ebs/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}

variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}

variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}

variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}

variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}

variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
48 changes: 48 additions & 0 deletions terraform-aws-ebs/vpc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink

tags = {
Name = var.tags
}
}

resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc_demo.id

tags = {
Name = "internet-gateway-demo"
}
}

resource "aws_subnet" "public_1" {
availability_zone = "us-east-1a"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"

tags = {
Name = "public_1-demo"
}
}

resource "aws_route_table" "route-public" {
vpc_id = aws_vpc.vpc_demo.id

route {
cidr_block = "10.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}

tags = {
Name = "public-route-table-demo"
}
}

resource "aws_route_table_association" "public_1" {
subnet_id = aws_subnet.public_1.id
route_table_id = aws_route_table.route-public.id
}

0 comments on commit f010a12

Please sign in to comment.