Moved AWS network resources into a aws-network module.
parent
a232bbfd71
commit
833352fda8
@ -0,0 +1,67 @@
|
|||||||
|
resource "aws_vpc" "vpc" {
|
||||||
|
cidr_block = var.vpc-cidr-block
|
||||||
|
tags = {
|
||||||
|
Name = "${var.name-prefix}-vpc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_subnet" "subnet" {
|
||||||
|
vpc_id = aws_vpc.vpc.id
|
||||||
|
cidr_block = var.subnet-cidr-block
|
||||||
|
# availability_zone = var.avail_zone
|
||||||
|
tags = {
|
||||||
|
Name = "${var.name-prefix}-subnet"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_default_security_group" "sg" {
|
||||||
|
vpc_id = aws_vpc.vpc.id
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
from_port = 22
|
||||||
|
to_port = 22
|
||||||
|
protocol = "tcp"
|
||||||
|
cidr_blocks = var.admin-ips
|
||||||
|
}
|
||||||
|
|
||||||
|
egress {
|
||||||
|
from_port = 0
|
||||||
|
to_port = 0
|
||||||
|
protocol = "-1"
|
||||||
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
|
prefix_list_ids = []
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "${var.name-prefix}-ssh-from-admins--sg"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_internet_gateway" "igw" {
|
||||||
|
vpc_id = aws_vpc.vpc.id
|
||||||
|
tags = {
|
||||||
|
Name = "${var.name-prefix}-igw"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_default_route_table" "route-table" {
|
||||||
|
default_route_table_id = aws_vpc.vpc.main_route_table_id
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "0.0.0.0/0"
|
||||||
|
gateway_id = aws_internet_gateway.igw.id
|
||||||
|
}
|
||||||
|
|
||||||
|
# default route, mapping VPC CIDR block to "local", created implicitly and
|
||||||
|
# cannot be specified.
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "${var.name-prefix}-route-table"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Associate subnet with Route Table
|
||||||
|
resource "aws_route_table_association" "a-rtb-subnet" {
|
||||||
|
subnet_id = aws_subnet.subnet.id
|
||||||
|
route_table_id = aws_default_route_table.route-table.id
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
output "vpc" {
|
||||||
|
value = aws_vpc.vpc
|
||||||
|
}
|
||||||
|
|
||||||
|
output "subnet" {
|
||||||
|
value = aws_subnet.subnet
|
||||||
|
}
|
||||||
|
|
||||||
|
output "default-security-group" {
|
||||||
|
value = aws_default_security_group.sg
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
variable "admin-ips" {
|
||||||
|
description = "A list of ips or cidr blocks that are allowed to connect to the nodes."
|
||||||
|
type = list(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "name-prefix" {
|
||||||
|
default = "tf"
|
||||||
|
description = "This prefix will be used in all the names of the resources creates in our AWS network."
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "subnet-cidr-block" {
|
||||||
|
default = "10.0.1.0/24"
|
||||||
|
description = "The address space to be used for this subnet."
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vpc-cidr-block" {
|
||||||
|
default = "10.0.0.0/16"
|
||||||
|
description = "The address space to be used for out networks VPC."
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue