-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservers.tf
72 lines (70 loc) · 2.32 KB
/
servers.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
## Query the latest AMI for Centos 7
data "aws_ami" "centos7" {
owners = ["679593333241"]
most_recent = true
filter {
name = "name"
values = ["CentOS Linux 7 x86_64 HVM EBS *"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
}
## SSH Key pair
resource "aws_key_pair" "terraform-demo-sshkey-santino" {
key_name = "terraform-demo-sshkey-santino"
public_key = file("~/.ssh/id_rsa.pub")
tags = {
Name = "terraform-demo-sshkey-santino"
}
}
### Server definitions
# Web server
resource "aws_instance" "terraform-demo-web" {
ami = data.aws_ami.centos7.id
instance_type = "t2.micro"
key_name = aws_key_pair.terraform-demo-sshkey-santino.key_name
subnet_id = aws_subnet.terraform-demo-snet-web.id
vpc_security_group_ids = [aws_security_group.terraform-demo-secgrp-webpub.id]
tags = {
Name = "terraform-demo-web"
}
}
# Application server
resource "aws_instance" "terraform-demo-app" {
ami = data.aws_ami.centos7.id
instance_type = "t2.micro"
key_name = aws_key_pair.terraform-demo-sshkey-santino.key_name
subnet_id = aws_subnet.terraform-demo-snet-app.id
vpc_security_group_ids = [aws_security_group.terraform-demo-secgrp-app.id]
tags = {
Name = "terraform-demo-app"
}
}
# Database server - Postgresql
resource "aws_instance" "terraform-demo-postgres" {
ami = data.aws_ami.centos7.id
instance_type = "t3a.medium"
key_name = aws_key_pair.terraform-demo-sshkey-santino.key_name
subnet_id = aws_subnet.terraform-demo-snet-db.id
vpc_security_group_ids = [aws_security_group.terraform-demo-secgrp-db.id]
tags = {
Name = "terraform-demo-postgres"
}
}
# Database server - MySQL
resource "aws_instance" "terraform-demo-mysql" {
ami = data.aws_ami.centos7.id
instance_type = "t3a.medium"
key_name = aws_key_pair.terraform-demo-sshkey-santino.key_name
subnet_id = aws_subnet.terraform-demo-snet-db.id
vpc_security_group_ids = [aws_security_group.terraform-demo-secgrp-db.id]
tags = {
Name = "terraform-demo-mysql"
}
}