forked from rootleveltech/rlt-hiring-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.tf
74 lines (63 loc) · 1.36 KB
/
test.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
// Credentials
provider "aws" {
access_key = ""
secret_key = ""
region = ""
}
// Security group
resource "aws_security_group" "testgroup" {
ingress {
from_port = 22
protocol = "TCP"
to_port = 22
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
protocol = "-1"
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
// Create instances
resource "aws_instance" "test_nginx" {
ami = "ami-759bc50a"
instance_type = "t2.micro"
key_name = "test"
security_groups = ["${aws_security_group.testgroup.name}"]
subnet_id = ""
tags {
name = "test_nginx"
}
provisioner "remote-exec" {
connection {
user = "ubuntu"
private_key = "${file("~/key/test.pem")}"
host = "${aws_instance.test_nginx.public_ip}"
}
inline = [
"sudo apt-get update",
"sudo apt-get install nginx -y",
"sudo ufw allow 'Nginx HTTP'",
"sudo chown -R ubuntu:ubuntu /var/www/",
"sudo echo \"1.0.6\" >> /var/www/html/version.txt"
]
}
}
// Creating db instance
resource "aws_db_instance" "test_db" {
instance_class = "db.t2.micro"
storage_type = "gp2"
engine = "MySQL"
engine_version = "5.7.22"
username = "master"
password = "test1test"
name = "test"
allocated_storage = 10
}