forked from toblich/tp-arq-aws
-
Notifications
You must be signed in to change notification settings - Fork 1
/
python.tf
99 lines (84 loc) · 2.35 KB
/
python.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
resource "aws_instance" "python" {
ami = "${var.ami_id}"
instance_type = "t2.micro"
key_name = "${var.key_pair_name}"
vpc_security_group_ids = ["${aws_security_group.apps.id}"]
tags {
Name = "tp_arqui_python"
}
# Store the resulting IP
provisioner "local-exec" {
command = "echo ${aws_instance.python.public_ip} > python/ip"
}
# Use the python app IP in node code
provisioner "local-exec" {
command = "sed -Ei.bak \"s/(remoteBaseUri:)[^,]*,/\\1 'http:\\/\\/$(cat python/ip):3000',/\" node/config.js"
}
# Environment setup
provisioner "remote-exec" {
inline = [
"echo ------- Create application directory: ${var.root} -------",
"mkdir ${var.root}",
]
connection {
type = "ssh"
user = "ec2-user"
private_key = "${file(var.private_key_location)}"
}
}
# Upload installer script
provisioner "file" {
source = "install_datadog.sh"
destination = "~/install_datadog.sh"
connection {
type = "ssh"
user = "ec2-user"
private_key = "${file(var.private_key_location)}"
}
}
# Execute installer script
provisioner "remote-exec" {
inline = [
"chmod +x ~/install_datadog.sh",
"~/install_datadog.sh ${var.datadog_key}",
]
connection {
type = "ssh"
user = "ec2-user"
private_key = "${file(var.private_key_location)}"
}
}
# Upload app
provisioner "file" {
source = "python/app.py"
destination = "${var.root}/app.py"
connection {
type = "ssh"
user = "ec2-user"
private_key = "${file(var.private_key_location)}"
}
}
provisioner "file" {
source = "python/requirements.txt"
destination = "${var.root}/requirements.txt"
connection {
type = "ssh"
user = "ec2-user"
private_key = "${file(var.private_key_location)}"
}
}
# Install app deps and run
provisioner "remote-exec" {
inline = [
"echo ------- Move into application directory: ${var.root} -------",
"cd ${var.root}",
"echo ------- Install dependencies -------",
"sudo pip install -r requirements.txt",
]
connection {
type = "ssh"
user = "ec2-user"
private_key = "${file(var.private_key_location)}"
}
}
}