-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpact-broker.tf
134 lines (113 loc) · 3.06 KB
/
pact-broker.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
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
resource "aws_security_group" "pact-broker" {
name = "pact-broker"
description = "pact broker ui and ssh"
/*vpc_id = "${var.aws_vpc}"*/
// These are for internal traffic
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
// These are for maintenance
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags {
Name = "pact broker security group"
}
}
resource "aws_instance" "server" {
ami = "${var.aws_ami}"
instance_type = "t2.small"
key_name = "${var.key_name}"
count = 1
security_groups = ["${aws_security_group.pact-broker.name}"]
associate_public_ip_address = "true"
tags {
Name = "pact-broker"
}
connection {
user = "ubuntu"
key_file = "${var.key_path}"
}
provisioner "file" {
source = "${path.module}/templates/nginx.conf"
destination = "/tmp/nginx.conf"
}
provisioner "file" {
source = "${path.module}/templates/pact-broker.sh"
destination = "/tmp/pact-broker.sh"
}
provisioner "file" {
source = "${template_file.rack.filename}"
destination = "/tmp/rack.conf"
}
provisioner "file" {
source = "${path.module}/templates/Gemfile"
destination = "/tmp/Gemfile"
}
provisioner "file" {
source = "${path.module}/templates/upstart.conf"
destination = "/tmp/upstart.conf"
}
provisioner "file" {
source = "${path.module}/templates/nginx-upstart.conf"
destination = "/tmp/nginx-upstart.conf"
}
# use this until files can be templated
provisioner "remote-exec" {
inline = [
"echo 'export DB_HOST=${var.db_host}' >> /tmp/postgres_vars",
"echo 'export DB_NAME=${var.db_name}' >> /tmp/postgres_vars",
"echo 'export DB_USERNAME=${var.db_username}' >> /tmp/postgres_vars",
"echo 'export DB_PASSWORD=${var.db_password}' >> /tmp/postgres_vars",
"echo 'export DB_URL=postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOST/$DB_NAME' >> /tmp/postgres_vars"
]
}
provisioner "remote-exec" {
scripts = [
"${path.module}/scripts/install.sh",
"${template_file.server.filename}",
"${path.module}/scripts/service.sh",
]
}
}
resource "aws_eip" "lb" {
instance = "${aws_instance.server.id}"
vpc = true
}
# this cannot be used for file provisioning yet, soon hopefully
resource "template_file" "rack" {
filename = "${path.module}/templates/rack.conf"
vars {
db_host = "${var.db_host}"
db_name = "${var.db_name}"
db_username = "${var.db_username}"
db_password = "${var.db_password}"
}
}
# this cannot be used for file provisioning yet, soon hopefully
resource "template_file" "server" {
filename = "${path.module}/scripts/server.sh"
vars {
db_host = "${var.db_host}"
db_name = "${var.db_name}"
db_username = "${var.db_username}"
db_password = "${var.db_password}"
}
}