-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathldap-slave.tf
More file actions
196 lines (173 loc) · 5.4 KB
/
ldap-slave.tf
File metadata and controls
196 lines (173 loc) · 5.4 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
data "template_file" "ldap-slave" {
template = "${file("./userdata-template/ldap-slave.tpl")}"
vars {
AWS_NETWORK_TYPE = "${var.aws_network_type}"
CONFIG_S3_BUCKET = "${var.config_s3_bucket}"
RES_S3_BUCKET = "${var.resource_s3_bucket}"
STAGE = "${var.environment}"
ROOTPW = "${var.ldap_rootpw}"
ROOTDN = "${var.ldap_rootdn}"
LDAP_ADMIN_GROUP = "${var.ldap_admin_group}"
MAINTENANCE_USER = "${var.maintenance_user}"
JENKINS_HOST = "${var.region}-jenkins"
}
}
# new ldap-slave exists on each regions per front / pet account
resource "aws_instance" "ldap-slave-01" {
depends_on = [
"aws_iam_role_policy_attachment.ldap-slave-read-resources3config-attach",
"aws_iam_role_policy_attachment.ldap-slave-reads3config-attach",
"aws_nat_gateway.public"
]
ami = "${var.ec2_ami}"
ebs_optimized = false
instance_type = "t3.micro"
monitoring = false
key_name = "${var.common_key}"
subnet_id = "${aws_subnet.private.0.id}"
vpc_security_group_ids = ["${aws_security_group.ldap-slave.id}"]
iam_instance_profile = "${aws_iam_instance_profile.ldap-slave.name}"
associate_public_ip_address = false
source_dest_check = true
disable_api_termination = false
user_data = "${data.template_file.ldap-slave.rendered}"
root_block_device {
volume_type = "gp2"
volume_size = 20
delete_on_termination = true
}
tags {
"Name" = "${var.region}-ldap-slave-01"
"Service" = "default"
"Segment" = "private"
"Role" = "ldap-slave"
"Env" = "${var.environment}"
"Country" = "jp"
"Cost" = "hogehoge"
}
volume_tags {
"Name" = "${var.region}-ldap-slave-01"
"Service" = "default"
"Segment" = "private"
"Role" = "ldap-slave"
"Env" = "${var.environment}"
"Country" = "jp"
"Cost" = "hogehoge"
}
lifecycle {
ignore_changes = [
"user_data",
"ami",
"instance_type",
"key_name",
"root_block_device.0.volume_type",
"subnet_id",
"vpc_security_group_ids",
"ebs_optimized"
]
}
}
resource "aws_instance" "ldap-slave-02" {
depends_on = [
"aws_iam_role_policy_attachment.ldap-slave-read-resources3config-attach",
"aws_iam_role_policy_attachment.ldap-slave-reads3config-attach",
"aws_nat_gateway.public"
]
ami = "${var.ec2_ami}"
ebs_optimized = false
instance_type = "t3.micro"
monitoring = false
key_name = "${var.common_key}"
subnet_id = "${aws_subnet.private.1.id}"
vpc_security_group_ids = ["${aws_security_group.ldap-slave.id}"]
iam_instance_profile = "${aws_iam_instance_profile.ldap-slave.name}"
associate_public_ip_address = false
source_dest_check = true
disable_api_termination = false
user_data = "${data.template_file.ldap-slave.rendered}"
root_block_device {
volume_type = "gp2"
volume_size = 20
delete_on_termination = true
}
tags {
"Name" = "${var.region}-ldap-slave-02"
"Service" = "default"
"Segment" = "private"
"Role" = "ldap-slave"
"Env" = "${var.environment}"
"Country" = "jp"
"Cost" = "hogehoge"
}
volume_tags {
"Name" = "${var.region}-ldap-slave-02"
"Service" = "default"
"Segment" = "private"
"Role" = "ldap-slave"
"Env" = "${var.environment}"
"Country" = "jp"
"Cost" = "hogehoge"
}
lifecycle {
ignore_changes = [
"user_data",
"ami",
"instance_type",
"key_name",
"root_block_device.0.volume_type",
"subnet_id",
"vpc_security_group_ids",
"ebs_optimized"
]
}
}
resource "aws_security_group" "ldap-slave" {
name = "ldap-slave-sg"
description = "LDAP-master Security Group"
vpc_id = "${aws_vpc.default-vpc.id}"
ingress {
from_port = 389
to_port = 389
protocol = "tcp"
cidr_blocks = ["${aws_vpc.default-vpc.cidr_block}"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${aws_vpc.default-vpc.cidr_block}"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags {
"Name" = "ldap-slave-sg"
"Service" = "default"
"Segment" = "private"
"Role" = "ldap-slave"
"Env" = "${var.environment}"
"Country" = "jp"
"Cost" = "hogehoge"
}
}
resource "aws_iam_instance_profile" "ldap-slave" {
name = "${var.region}-ldap-slave"
role = "${aws_iam_role.ldap-slave.name}"
}
resource "aws_iam_role" "ldap-slave" {
name = "${var.region}-ldap-slave"
assume_role_policy = "${file("./policy/iam_assumerole.json")}"
}
resource "aws_iam_role_policy_attachment" "ldap-slave-reads3config-attach" {
depends_on = ["aws_iam_role.ldap-slave", "aws_iam_policy.r_s3_cnf"]
role = "${aws_iam_role.ldap-slave.name}"
policy_arn = "arn:aws:iam::${data.aws_caller_identity.self.account_id}:policy/${var.region}-ReadS3Config"
}
resource "aws_iam_role_policy_attachment" "ldap-slave-read-resources3config-attach" {
depends_on = ["aws_iam_role.ldap-slave"]
role = "${aws_iam_role.ldap-slave.name}"
policy_arn = "arn:aws:iam::${data.aws_caller_identity.self.account_id}:policy/${var.region}-ReadResourceS3Config"
}