-
Notifications
You must be signed in to change notification settings - Fork 1
/
aws.tf
81 lines (66 loc) · 2.03 KB
/
aws.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
provider "aws" {
access_key = "${var.aws_keys["access"]}"
secret_key = "${var.aws_keys["secret"]}"
region = "${var.aws_region}"
}
resource "aws_elb" "web" {
name = "${var.user_prefix}-elb"
subnets = ["${aws_subnet.default.id}"]
security_groups = ["${aws_security_group.elb.id}"]
# The instances are registered automatically
instances = ["${aws_instance.web.*.id}"]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 3
timeout = 10
target = "HTTP:80/index.html"
interval = 30
}
}
resource "aws_instance" "ansible" {
tags = {
Name = "${var.user_prefix}-ansible"
group = "ansible_master"
}
instance_type = "m1.small"
ami = "${lookup(var.aws_amis, var.aws_region)}"
subnet_id = "${aws_subnet.default.id}"
vpc_security_group_ids = ["${aws_security_group.ansible.id}"]
connection {
# The default username for our AMI
user = "ubuntu"
private_key = "${file("demo.pem")}"
}
key_name = "demo"
provisioner "remote-exec" {
inline = [
"sudo apt-get -y install python-software-properties",
"sudo apt-add-repository -y ppa:ansible/ansible",
"sudo apt-get -y update",
"sudo apt-get -y install ansible",
]
}
}
resource "aws_instance" "web" {
tags = {
Name = "${var.user_prefix}-web-${count.index}"
group = "web"
}
instance_type = "m1.small"
ami = "${lookup(var.aws_amis, var.aws_region)}"
key_name = "demo"
# Our Security group to allow HTTP and SSH access
vpc_security_group_ids = ["${aws_security_group.default.id}"]
# We're going to launch into the same subnet as our ELB. In a production
# environment it's more common to have a separate private subnet for
# backend instances.
subnet_id = "${aws_subnet.default.id}"
# This will create a number of instances idicated below
count = "${var.aws_instances_count}"
}