Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
easyawslearn committed Oct 9, 2019
1 parent 604898a commit 77cdd87
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
39 changes: 39 additions & 0 deletions terraform-aws-private-public-ip/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,46 @@ variable "instance_type" {
default = "t2.micro"
}

variable "device_name" {
type = "string"
default = "/dev/xvdh"
}
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"
}
77 changes: 77 additions & 0 deletions terraform-aws-private-public-ip/vpc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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
}

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"]
}

ingress {
# SSH Port 80 allowed from any IP
from_port = 80
to_port = 80
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"]
}
}

0 comments on commit 77cdd87

Please sign in to comment.