-
Notifications
You must be signed in to change notification settings - Fork 3
/
terraform_101.tf
108 lines (83 loc) · 1.9 KB
/
terraform_101.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
# region: eu-west-1
# ami: ami-c0cff0a6
provider "aws" {
region = "${var.aws_region}"
//shared_credentials_file = "/credentials"
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["${var.ami_search_path}"]
}
owners = ["${var.cannonical_owner_id}"]
}
resource "aws_security_group" "devoxx" {
ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Owner = "${var.owner}"
Name = "devoxx_terraform101_slot"
}
}
resource "aws_key_pair" "devoxx" {
public_key = "${file("ssh/rsakey.pub")}"
}
resource "aws_instance" "devoxx" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "m3.medium"
key_name = "${aws_key_pair.devoxx.key_name}"
# security group name here
security_groups = ["${aws_security_group.devoxx.name}"]
count = "${var.node_count}"
provisioner "remote-exec" {
inline = "sleep 1"
connection {
user = "ubuntu"
private_key = "${file("ssh/rsakey")}"
}
}
tags = {
Owner = "${var.owner}"
Name = "devoxx_terraform101_slot"
}
}
resource "aws_elb" "devoxx" {
# refactor this
availability_zones = ["${aws_instance.devoxx.*.availability_zone}"]
listener {
instance_port = 8080
instance_protocol = "tcp"
lb_port = 80
lb_protocol = "tcp"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 5
target = "TCP:8080"
interval = 5
timeout = 4
}
instances = ["${aws_instance.devoxx.*.id}"]
tags = {
Owner = "${var.owner}"
Name = "devoxx_terraform101_slot"
}
}
data "aws_route53_zone" "xebia_dns" {
name = "${var.xebia_dns}"
}
resource "aws_route53_record" "devoxx" {
zone_id = "${data.aws_route53_zone.xebia_dns.id}"
name = "devoxx"
type = "A"
alias {
name = "${aws_elb.devoxx.dns_name}"
zone_id = "${aws_elb.devoxx.zone_id}"
evaluate_target_health = true
}
}