-
Notifications
You must be signed in to change notification settings - Fork 1
/
ec2-machines.tf
100 lines (95 loc) · 3.33 KB
/
ec2-machines.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
resource "aws_route53_record" "airflow" {
zone_id = "ZBVO8OQHTFSNO"
name = "airflow.erich.com"
type = "CNAME"
ttl = "60"
records = ["${aws_instance.airflow.public_dns}"]
}
resource "aws_instance" "airflow" {
ami = "${lookup(var.AmiLinux, var.region)}"
instance_type = "t2.micro"
associate_public_ip_address = "true"
subnet_id = "${aws_subnet.PublicAZA.id}"
vpc_security_group_ids = ["${aws_security_group.FrontEnd.id}"]
key_name = "${var.key_name}"
# TODO: make this instance profile have access to private chef bucket
iam_instance_profile = "${aws_iam_instance_profile.ssm_profile.id}"
provisioner "file" {
source = "/Users/ej/.ssh/id_rsa"
destination = "/home/ec2-user/.ssh/id_rsa"
connection {
user = "ec2-user"
agent = "false"
type = "ssh"
private_key = "${file("/Users/ej/.ssh/ej_key_pair.pem")}"
timeout = "300s"
}
}
provisioner "file" {
source = "./files/airflow_user_data.sh"
destination = "/home/ec2-user/airflow_user_data.sh"
connection {
user = "ec2-user"
agent = "false"
type = "ssh"
private_key = "${file("/Users/ej/.ssh/ej_key_pair.pem")}"
timeout = "300s"
}
}
provisioner "file" {
source = "./files/airflow-webserver.conf"
destination = "/home/ec2-user/airflow-webserver.conf"
connection {
user = "ec2-user"
agent = "false"
type = "ssh"
private_key = "${file("/Users/ej/.ssh/ej_key_pair.pem")}"
timeout = "300s"
}
}
provisioner "remote-exec" {
inline = [
"chmod +x /home/ec2-user/airflow_user_data.sh",
"/home/ec2-user/airflow_user_data.sh",
]
connection {
user = "ec2-user"
agent = "false"
type = "ssh"
private_key = "${file("/Users/ej/.ssh/ej_key_pair.pem")}"
timeout = "300s"
}
}
tags {
Name = "airflow"
Environment = "Test"
}
}
#"airflow initdb",
#"nohup airflow webserver &",
resource "aws_iam_instance_profile" "ssm_profile" {
name = "ssm_profile"
role = "${aws_iam_role.ssm_role.name}"
}
resource "aws_iam_role" "ssm_role" {
name = "ssm_role"
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{ "Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
data "aws_iam_policy" "ReadOnlyAccess"
{
arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}