-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2.tf
104 lines (90 loc) · 3.15 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
96
97
98
99
100
101
102
103
104
resource "aws_instance" "instance_a" { //Instance A
ami = var.ami
instance_type = "t2.micro"
subnet_id = var.subnet_a
key_name = "tfserverkey"
tags = {
Name = "Instance A"
}
user_data = <<-EOF
#!/bin/bash
sudo apt-get update
sudo apt-get install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
echo '<!doctype html>
<html lang="en"><h1>Home page!</h1></br>
<h3>(Instance A)</h3>
</html>' | sudo tee /var/www/html/index.html
EOF
}
resource "aws_instance" "instance_b" { //Instance B
ami = var.ami
instance_type = "t2.micro"
subnet_id = var.subnet_b
key_name = "tfserverkey"
tags = {
Name = "Instance B"
}
user_data = <<-EOF
#!/bin/bash
sudo apt-get update
sudo apt-get install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
echo '<!doctype html>
<html lang="en"><h1>Images!</h1></br>
<h3>(Instance B)</h3>
</html>' | sudo tee /var/www/html/index.html
echo 'server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location /images/ {
alias /var/www/html/;
index index.html;
}
location / {
try_files $uri $uri/ =404;
}
}' | sudo tee /etc/nginx/sites-available/default
sudo systemctl reload nginx
EOF
}
resource "aws_instance" "instance_c" { //Instance C
ami = var.ami
instance_type = "t2.micro"
subnet_id = var.subnet_c
key_name = "tfserverkey"
tags = {
Name = "Instance C"
}
user_data = <<-EOF
#!/bin/bash
sudo apt-get update
sudo apt-get install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
echo '<!doctype html>
<html lang="en"><h1>Register!</h1></br>
<h3>(Instance C)</h3>
</html>' | sudo tee /var/www/html/index.html
echo 'server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location /register/ {
alias /var/www/html/;
index index.html;
}
location / {
try_files $uri $uri/ =404;
}
}' | sudo tee /etc/nginx/sites-available/default
sudo systemctl reload nginx
EOF
}