forked from google/trillian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterraform.tf
157 lines (130 loc) · 3.71 KB
/
terraform.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
variable "WHITELIST_CIDR" {
description="Your IP block to whitelist access from"
}
variable "MYSQL_ROOT_PASSWORD" { }
provider "aws" {
region = "us-west-2"
}
/* The Database */
resource "aws_rds_cluster" "trillian" {
cluster_identifier = "trillian"
database_name = "test"
master_username = "root"
master_password = "${var.MYSQL_ROOT_PASSWORD}"
skip_final_snapshot = true
port = 3306
vpc_security_group_ids = ["${aws_security_group.trillian_db.id}"]
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
storage_encrypted = true
apply_immediately = true
}
resource "aws_rds_cluster_instance" "cluster_instances" {
count = 2
identifier = "trillian-${count.index}"
cluster_identifier = "${aws_rds_cluster.trillian.id}"
instance_class = "db.r3.large"
publicly_accessible = true
apply_immediately = true
}
resource "aws_security_group" "trillian_db" {
name = "trillian-db"
description = "Allow MySQL from Trillian and Development CIDR"
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["${var.WHITELIST_CIDR}"]
}
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
security_groups = ["${aws_security_group.trillian.id}"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_rds_cluster_parameter_group" "trillian" {
name = "trillian-pg"
family = "aurora5.6"
# Whether InnoDB returns errors rather than warnings for exceptional conditions.
# replaces: `sql_mode = STRICT_ALL_TABLES`
parameter {
name = "innodb_strict_mode"
value = "1"
}
}
/* The Instance */
/* select the latest official hvm amazon linux release */
data "aws_ami" "trillian" {
most_recent = true
executable_users = ["all"]
name_regex = "^amzn-ami-hvm"
owners = ["amazon"]
}
resource "aws_security_group" "trillian" {
name = "trillian"
description = "Expose Rest, TPC and SSH endpoint to local cidr"
ingress {
from_port = 8090
to_port = 8091
protocol = "tcp"
cidr_blocks = ["${var.WHITELIST_CIDR}"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${var.WHITELIST_CIDR}"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "trillian" {
ami = "${data.aws_ami.trillian.id}"
instance_type = "t2.medium"
vpc_security_group_ids = ["${aws_security_group.trillian.id}"]
associate_public_ip_address = true
tags {
Name = "trillian"
}
user_data = <<EOF
#!/bin/bash
set -e
yum update -y
yum install -y git mysql
# install golang
curl -o /tmp/go.tar.gz https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
tar -C /usr/local -xzf /tmp/go.tar.gz
export PATH=$PATH:/usr/local/go/bin
mkdir -p /go
export GOPATH=/go
# Install Trillian
go get github.com/google/trillian/cmd/trillian_log_server
# Setup the DB
cd /go/src/github.com/google/trillian
export MYSQL_ROOT_USER=root
export MYSQL_ROOT_PASSWORD=${var.MYSQL_ROOT_PASSWORD}
export MYSQL_HOST=${aws_rds_cluster.trillian.endpoint}
export MYSQL_DATABASE=test
export MYSQL_USER=test
export MYSQL_PASSWORD=zaphod
./scripts/resetdb.sh --verbose --force
# Startup the Server
RPC_PORT=8090
HTTP_PORT=8091
/go/bin/trillian_log_server \
--mysql_uri="${MYSQL_USER}:${MYSQL_PASSWORD}@tcp(${MYSQL_HOST})/${MYSQL_DATABASE}" \
--rpc_endpoint="$HOST:$RPC_PORT" \
--http_endpoint="$HOST:$HTTP_PORT" \
--alsologtostderr
EOF
}