This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
consul.tf
102 lines (89 loc) · 3.18 KB
/
consul.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
data "aws_iam_policy_document" "consul-assume-role-policy" {
statement {
effect = "Allow"
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com"
]
}
}
}
resource "aws_iam_role" "consul-role" {
name = "ConsulRole"
assume_role_policy = "${data.aws_iam_policy_document.consul-assume-role-policy.json}"
}
resource "aws_iam_role_policy_attachment" "consul-access-policy" {
role = "${aws_iam_role.consul-role.name}"
policy_arn = "${lookup(var.unmanaged_role_arns, "mozdef-logging")}"
}
resource "aws_iam_instance_profile" "consul-profile" {
name = "consul-profile"
roles = ["${aws_iam_role.consul-role.name}"]
}
resource "aws_security_group" "consul-shared-ec2-sg" {
name = "consul-shared-ec2-sg"
description = "Consul SG"
vpc_id = "${aws_vpc.apps-shared-vpc.id}"
}
resource "aws_security_group_rule" "consul-shared-ec2-sg-allowallfromprodstaging" {
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["${aws_vpc.apps-staging-vpc.cidr_block}", "${aws_vpc.apps-production-vpc.cidr_block}", "${aws_vpc.apps-shared-vpc.cidr_block}"]
security_group_id = "${aws_security_group.consul-shared-ec2-sg.id}"
}
resource "aws_security_group_rule" "consul-shared-ec2-sg-allowall" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.consul-shared-ec2-sg.id}"
}
resource "aws_launch_configuration" "consul-shared-ec2-lc" {
name_prefix = "consul-shared-ec2-lc-"
image_id = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "t2.micro"
key_name = "ansible"
security_groups = ["${aws_security_group.consul-shared-ec2-sg.id}"]
iam_instance_profile = "${aws_iam_instance_profile.consul-profile.name}"
associate_public_ip_address = true
root_block_device {
volume_size = 100
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "consul-shared-ec2-as" {
name = "consul-shared-ec2-as"
launch_configuration = "${aws_launch_configuration.consul-shared-ec2-lc.id}"
availability_zones = ["${split(",", lookup(var.aws_availibility_zones, var.aws_region))}"]
max_size = 5
desired_capacity = 3
min_size = 3
vpc_zone_identifier = ["${aws_subnet.apps-shared-1a.id}", "${aws_subnet.apps-shared-1c.id}", "${aws_subnet.apps-shared-1d.id}"]
tag {
key = "app"
value = "consul"
propagate_at_launch = true
}
tag {
key = "env"
value = "shared"
propagate_at_launch = true
}
tag {
key = "Name"
value = "consul"
propagate_at_launch = true
}
lifecycle {
create_before_destroy = true
}
}