July 2017
Intermediate to advanced
374 pages
8h
English
Add following code to main.tf for the creation of a security group for the MongoDB server:
resource "aws_security_group" "mongodb" {
name = "cna-sg-mongodb"
description = "Security group of mongodb server"
vpc_id = "${aws_vpc.default.id}"
# SSH access from anywhere
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# HTTP access from the VPC
ingress {
from_port = 27017
to_port = 27017
protocol = "tcp"
cidr_blocks = ["${var.vpc_cidr}"]
}
# HTTP access from the VPC
ingress {
from_port = 28017
to_port = 28017
protocol = "tcp"
cidr_blocks = ["${var.vpc_cidr}"]
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
Next, ...