-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
94 lines (84 loc) · 2.13 KB
/
main.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
# Specify the provider and access details
provider "aws" {
region = "${var.aws_region}"
}
resource "aws_elb" "web-elb" {
name = "terraform-example-elb"
# The same availability zone as our instances
availability_zones = ["${split(",", var.availability_zones)}"]
listener {
instance_port = 8080
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "HTTP:8080/"
interval = 30
}
}
resource "aws_autoscaling_group" "web-asg" {
availability_zones = ["${split(",", var.availability_zones)}"]
name = "terraform-example-asg"
max_size = "${var.asg_max}"
min_size = "${var.asg_min}"
desired_capacity = "${var.asg_desired}"
force_delete = true
launch_configuration = "${aws_launch_configuration.web-lc.name}"
load_balancers = ["${aws_elb.web-elb.name}"]
#vpc_zone_identifier = ["${split(",", var.availability_zones)}"]
tag {
key = "Name"
value = "web-asg"
propagate_at_launch = "true"
}
}
resource "aws_launch_configuration" "web-lc" {
image_id = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "${var.instance_type}"
# Security group
security_groups = ["${aws_security_group.default.id}"]
user_data = "${file("userdata.sh")}"
key_name = "${var.key_name}"
lifecycle {
create_before_destroy = true
}
}
# Our default security group to access
# the instances over SSH and HTTP
resource "aws_security_group" "default" {
name = "terraform_example_sg"
description = "Used in the terraform"
# SSH access from anywhere
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# HTTP access from anywhere
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# HTTP/8080 access from anywhere
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
#cidr_blocks = ["0.0.0.0/0"]
security_groups = [ "sg-7a148402" ]
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}