Skip to content

Commit 8c15218

Browse files
committed
added route53/rds
1 parent 77cdd87 commit 8c15218

File tree

17 files changed

+948
-0
lines changed

17 files changed

+948
-0
lines changed

EIP_PrivateIP_route53/instance.tf

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
provider "aws" {
2+
region = "${var.region}"
3+
version = "~> 2.0"
4+
}
5+
6+
7+
resource "aws_instance" "IP_example" {
8+
ami = lookup(var.ami_id, var.region)
9+
instance_type = var.instance_type
10+
subnet_id = aws_subnet.public_1.id
11+
12+
# Security group assign to instance
13+
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
14+
private_ip = "10.0.1.10"
15+
# key name
16+
key_name = var.key_name
17+
18+
user_data = <<EOF
19+
#! /bin/bash
20+
sudo yum update -y
21+
sudo yum install -y httpd.x86_64
22+
sudo service httpd start
23+
sudo service httpd enable
24+
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
25+
EOF
26+
27+
tags = {
28+
Name = "Private_IP"
29+
}
30+
}
31+
32+
resource "aws_eip" "eip" {
33+
instance = aws_instance.IP_example.id
34+
vpc = true
35+
}
36+
37+
output "public_ip" {
38+
value = aws_instance.IP_example.public_ip
39+
}

EIP_PrivateIP_route53/route53.tf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_route53_zone" "easy_aws" {
2+
name = "easyaws.in"
3+
4+
tags = {
5+
Environment = "dev"
6+
}
7+
}
8+
9+
resource "aws_route53_record" "www" {
10+
zone_id = aws_route53_zone.easy_aws.zone_id
11+
name = "www.easyaws.in"
12+
type = "A"
13+
ttl = "300"
14+
records = [aws_eip.eip.public_ip]
15+
}
16+
17+
output "name_server"{
18+
value=aws_route53_zone.easy_aws.name_servers
19+
}

EIP_PrivateIP_route53/variables.tf

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
18+
variable "device_name" {
19+
type = "string"
20+
default = "/dev/xvdh"
21+
}
22+
variable "key_name" {
23+
type = "string"
24+
default = "ec2-demo"
25+
}
26+
27+
variable "cidr" {
28+
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
29+
type = string
30+
default = "10.0.0.0/16"
31+
}
32+
variable "instance_tenancy" {
33+
description = "A tenancy option for instances launched into the VPC"
34+
type = string
35+
default = "default"
36+
}
37+
38+
variable "enable_dns_hostnames" {
39+
description = "Should be true to enable DNS hostnames in the VPC"
40+
type = bool
41+
default = true
42+
}
43+
44+
variable "enable_dns_support" {
45+
description = "Should be true to enable DNS support in the VPC"
46+
type = bool
47+
default = true
48+
}
49+
50+
variable "enable_classiclink" {
51+
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
52+
type = bool
53+
default = false
54+
}
55+
56+
variable "tags" {
57+
description = "A map of tags to add to all resources"
58+
type = string
59+
default = "Vpc-custom-demo"
60+
}

EIP_PrivateIP_route53/vpc.tf

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}
49+
50+
resource "aws_security_group" "allow_ssh" {
51+
name = "allow_SSH"
52+
description = "Allow SSH inbound traffic"
53+
vpc_id = aws_vpc.vpc_demo.id
54+
55+
ingress {
56+
# SSH Port 22 allowed from any IP
57+
from_port = 22
58+
to_port = 22
59+
protocol = "tcp"
60+
cidr_blocks = ["0.0.0.0/0"]
61+
}
62+
63+
ingress {
64+
# SSH Port 80 allowed from any IP
65+
from_port = 80
66+
to_port = 80
67+
protocol = "tcp"
68+
cidr_blocks = ["0.0.0.0/0"]
69+
}
70+
71+
egress {
72+
from_port = 0
73+
to_port = 0
74+
protocol = "-1"
75+
cidr_blocks = ["0.0.0.0/0"]
76+
}
77+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
provider "aws" {
2+
region = "${var.region}"
3+
version = "~> 2.0"
4+
}
5+
6+
7+
resource "aws_instance" "IP_example" {
8+
ami = lookup(var.ami_id, var.region)
9+
instance_type = var.instance_type
10+
subnet_id = aws_subnet.public_1.id
11+
12+
# Security group assign to instance
13+
vpc_security_group_ids = [aws_security_group.allow_ssh_http.id]
14+
availability_zone="us-east-1a"
15+
# key name
16+
key_name = var.key_name
17+
18+
user_data = <<EOF
19+
#! /bin/bash
20+
sudo yum update -y
21+
sudo yum install -y httpd.x86_64
22+
sudo service httpd start
23+
sudo service httpd enable
24+
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
25+
EOF
26+
27+
tags = {
28+
Name = "RDS_MariaDB_Example"
29+
}
30+
}
31+
32+
33+
output "public_ip" {
34+
value = aws_instance.IP_example.public_ip
35+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
resource "aws_db_parameter_group" "default" {
2+
name = "mariadb"
3+
family = "mariadb10.2"
4+
5+
parameter {
6+
name = "max_allowed_packet"
7+
value = "16777216"
8+
}
9+
}
10+
11+
resource "aws_db_subnet_group" "default" {
12+
name = "main"
13+
subnet_ids = [aws_subnet.private_1.id, aws_subnet.private_2.id]
14+
15+
tags = {
16+
Name = "My DB subnet group"
17+
}
18+
}
19+
20+
resource "aws_db_instance" "default" {
21+
allocated_storage = 20
22+
storage_type = "gp2"
23+
engine = "mariadb"
24+
engine_version = "10.2.21"
25+
instance_class = "db.t2.micro"
26+
name = "mydb"
27+
username = "root"
28+
password = "foobarbaz"
29+
parameter_group_name = "mariadb"
30+
db_subnet_group_name=aws_db_subnet_group.default.name
31+
vpc_security_group_ids=[aws_security_group.db.id]
32+
availability_zone=aws_subnet.private_1.availability_zone
33+
}
34+
35+
output "end_point" {
36+
value = aws_db_instance.default.endpoint
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
resource "aws_security_group" "allow_ssh_http" {
2+
name = "allow_SSH_http"
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+
ingress {
15+
# SSH Port 80 allowed from any IP
16+
from_port = 80
17+
to_port = 80
18+
protocol = "tcp"
19+
cidr_blocks = ["0.0.0.0/0"]
20+
}
21+
22+
egress {
23+
from_port = 0
24+
to_port = 0
25+
protocol = "-1"
26+
cidr_blocks = ["0.0.0.0/0"]
27+
}
28+
}
29+
30+
resource "aws_security_group" "db" {
31+
name = "allow_SSH"
32+
description = "Allow SSH inbound traffic"
33+
vpc_id = aws_vpc.vpc_demo.id
34+
35+
ingress {
36+
# SSH Port 22 allowed from any IP
37+
from_port = 3306
38+
to_port = 3306
39+
protocol = "tcp"
40+
security_groups =[aws_security_group.allow_ssh_http.id]
41+
}
42+
43+
egress {
44+
from_port = 0
45+
to_port = 0
46+
protocol = "-1"
47+
cidr_blocks = ["0.0.0.0/0"]
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
18+
variable "device_name" {
19+
type = "string"
20+
default = "/dev/xvdh"
21+
}
22+
variable "key_name" {
23+
type = "string"
24+
default = "ec2-demo"
25+
}
26+
27+
variable "cidr" {
28+
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
29+
type = string
30+
default = "10.0.0.0/16"
31+
}
32+
variable "instance_tenancy" {
33+
description = "A tenancy option for instances launched into the VPC"
34+
type = string
35+
default = "default"
36+
}
37+
38+
variable "enable_dns_hostnames" {
39+
description = "Should be true to enable DNS hostnames in the VPC"
40+
type = bool
41+
default = true
42+
}
43+
44+
variable "enable_dns_support" {
45+
description = "Should be true to enable DNS support in the VPC"
46+
type = bool
47+
default = true
48+
}
49+
50+
variable "enable_classiclink" {
51+
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
52+
type = bool
53+
default = false
54+
}
55+
56+
variable "tags" {
57+
description = "A map of tags to add to all resources"
58+
type = string
59+
default = "Vpc-custom-demo"
60+
}

0 commit comments

Comments
 (0)