-
Notifications
You must be signed in to change notification settings - Fork 2
/
ec2.tf
95 lines (90 loc) · 2.67 KB
/
ec2.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
### EC2 - Instances
### Criação de EC2 para DBservers
resource "aws_instance" "DB01" {
ami = "ami-00068cd7555f543d5"
instance_type = "t2.micro"
### VPC
subnet_id = aws_subnet.prod-subnet-private-1.id
availability_zone = var.AWS_REGION_AZ_DB
### Atribuir Security Group
vpc_security_group_ids = [aws_security_group.dbservers.id]
### Chave pública utilizada
key_name = aws_key_pair.minha-chave-ssh.id
### Script para deploy de banco de dados MariaDB/MySQL
user_data = file("userdatadb.sh")
connection {
user = "ec2-user"
private_key = file(var.PRIVATE_KEY_PATH)
}
tags = {
Name = "DB01"
}
}
### Criação de EC2 para Webservers
resource "aws_instance" "WEB01" {
ami = "ami-00068cd7555f543d5"
instance_type = "t2.micro"
### VPC
subnet_id = aws_subnet.prod-subnet-public-1.id
availability_zone = var.AWS_REGION_AZ_WEB_1
### Atribuir Security Group
vpc_security_group_ids = [aws_security_group.webservers.id]
### Chave pública utilizada
key_name = aws_key_pair.minha-chave-ssh.id
### Script para deploy de servidor web
user_data = file("userdataweb.sh")
connection {
user = "ec2-user"
private_key = file(var.PRIVATE_KEY_PATH)
}
tags = {
Name = "WEB01"
}
}
### Criação de EC2 para Webservers
resource "aws_instance" "WEB02" {
ami = "ami-00068cd7555f543d5"
instance_type = "t2.micro"
### VPC
subnet_id = aws_subnet.prod-subnet-public-2.id
availability_zone = var.AWS_REGION_AZ_WEB_2
### Atribuir Security Group
vpc_security_group_ids = [aws_security_group.webservers.id]
### Chave pública utilizada
key_name = aws_key_pair.minha-chave-ssh.id
### Script para deploy de servidor web
user_data = file("userdataweb.sh")
connection {
user = "ec2-user"
private_key = file(var.PRIVATE_KEY_PATH)
}
tags = {
Name = "WEB02"
}
}
resource "aws_instance" "WEB03" {
ami = "ami-00068cd7555f543d5"
instance_type = "t2.micro"
### VPC
subnet_id = aws_subnet.prod-subnet-public-3.id
availability_zone = var.AWS_REGION_AZ_WEB_3
### Atribuir Security Group
vpc_security_group_ids = [aws_security_group.webservers.id]
### Chave pública utilizada
key_name = aws_key_pair.minha-chave-ssh.id
### Script para deploy de servidor web
user_data = file("userdataweb.sh")
connection {
user = "ec2-user"
private_key = file(var.PRIVATE_KEY_PATH)
}
tags = {
Name = "WEB03"
}
}
### Chave pública que deve ser enviada para as EC2 no momento do deploy
### para criar, basta digitar no diretorio raiz : ssh-keygen -f minha-chave-ssh
resource "aws_key_pair" "minha-chave-ssh" {
key_name = "minha-chave-ssh"
public_key = file(var.PUBLIC_KEY_PATH)
}