-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
257 lines (217 loc) · 9.39 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
provider "aws" {}
locals {
deployment_name = var.application_name
}
data "local_file" "automate_license" {
filename = "automate.license"
}
data "aws_caller_identity" "current" {
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
data "aws_route53_zone" "zone" {
name = "${var.domain}."
private_zone = false
}
# https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/1.37.0
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = local.deployment_name
cidr = var.vpc["cidr_block"]
azs = keys(var.az_subnets)
# private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = values(var.az_subnets)
# enable_nat_gateway = true
# enable_vpn_gateway = true
tags = var.default_tags
}
module "security_groups" {
source = "./security_groups"
create_chef_ha = var.create_chef_ha
account_id = data.aws_caller_identity.current.account_id
default_tags = var.default_tags
deployment_name = local.deployment_name
ssh_whitelist_cidrs = var.ssh_whitelist_cidrs
vpc_id = module.vpc.vpc_id
zone_id = data.aws_route53_zone.zone.id
}
module "chef_automate2" {
source = "./chef_automate2"
ami = data.aws_ami.ubuntu.id
ami_user = var.ami_user
automate_fqdn = module.chef_alb.automate_alb_fqdn
automate_license = chomp(data.local_file.automate_license.content)
default_tags = var.default_tags
deployment_name = local.deployment_name
domain = var.domain
https_security_group_id = module.security_groups.https_security_group_id
instance = var.instance
hostnames = var.hostnames
instance_keys = var.instance_keys
r53_ttl = var.r53_ttl
ssh_security_group_id = module.security_groups.ssh_security_group_id
subnet = element(module.vpc.public_subnets, 1 % length(keys(var.az_subnets)))
zone_id = data.aws_route53_zone.zone.id
}
module "chef_server" {
source = "./chef_server"
create_chef_server = var.create_chef_server
ami = data.aws_ami.ubuntu.id
ami_user = var.ami_user
automate_fqdn = module.chef_alb.automate_alb_fqdn
chef_server_version = var.chef_frontend["version"]
data_collector_token = module.chef_automate2.data_collector_token
default_tags = var.default_tags
deployment_name = local.deployment_name
domain = var.domain
hostnames = var.hostnames
https_security_group_id = module.security_groups.https_security_group_id
instance = var.instance
instance_keys = var.instance_keys
r53_ttl = var.r53_ttl
ssh_security_group_id = module.security_groups.ssh_security_group_id
subnet = element(module.vpc.public_subnets, 1 % length(keys(var.az_subnets)))
zone_id = data.aws_route53_zone.zone.id
}
module "chef_ha" {
source = "./chef_ha"
create_chef_ha = var.create_chef_ha
account_id = data.aws_caller_identity.current.account_id
ami = data.aws_ami.ubuntu.id
ami_user = var.ami_user
automate_fqdn = module.chef_alb.automate_alb_fqdn
az_subnet_ids = module.vpc.public_subnets
backend_security_group_id = module.security_groups.backend_security_group_id
chef_backend = var.chef_backend
chef_frontend = var.chef_frontend
data_collector_token = module.chef_automate2.data_collector_token
default_tags = var.default_tags
deployment_name = local.deployment_name
domain = var.domain
hostnames = var.hostnames
https_security_group_id = module.security_groups.https_security_group_id
instance = var.instance
instance_keys = var.instance_keys
ssh_security_group_id = module.security_groups.ssh_security_group_id
vpc = var.vpc
vpc_id = module.vpc.vpc_id
zone_id = data.aws_route53_zone.zone.id
}
module "chef_alb" {
source = "./chef_alb"
account_id = data.aws_caller_identity.current.account_id
subnets = module.vpc.public_subnets
deployment_name = local.deployment_name
domain = var.domain
hostnames = var.hostnames
https_security_group_id = module.security_groups.https_security_group_id
log_bucket = var.log_bucket
chef_target_ids = concat(
module.chef_ha.frontend_ids,
module.chef_server.chef_server_id,
)
chef_target_count = var.create_chef_ha ? var.chef_frontend["count"] : 1
automate_target_ids = module.chef_automate2.chef_automate_ids
vpc_id = module.vpc.vpc_id
zone_id = data.aws_route53_zone.zone.id
}
module "chef_unattended_registration" {
source = "./chef_unattended_registration"
create_unattended_registration = var.create_chef_ha || var.create_chef_server ? 1 : 0
account_id = data.aws_caller_identity.current.account_id
validator_key_path = var.validator_key_path
}
module "test_org_setup" {
source = "./test_org_setup"
create_test_org = var.create_chef_ha || var.create_chef_server ? 1 : 0
# server_ready is an inter-module dependency workaround to ensure that the org doesn't get created until chef server/all front ends are configured
server_ready = concat(
module.chef_ha.data_collector_configured,
module.chef_server.data_collector_configured,
)
ami_user = var.ami_user
automate_fqdn = module.chef_alb.automate_alb_fqdn
chef_server_fqdn = module.chef_alb.chef_alb_fqdn
automate_server_public_ip = element(module.chef_automate2.chef_automate_public_ip, 0)
chef_server_ids = concat(
module.chef_ha.frontend_ids,
module.chef_server.chef_server_id,
)
chef_server_public_ip = concat(
module.chef_ha.chef_server_public_ip,
module.chef_server.chef_server_public_ip,
)
data_collector_token = module.chef_automate2.data_collector_token
instance_keys = var.instance_keys
validator_key_path = var.validator_key_path
}
module "chef_clients" {
source = "./chef_clients"
# server_ready is an inter-module dependency workaround to ensure that the clients don't get created until chef server and alb is created
server_ready = concat(
module.chef_ha.data_collector_configured,
module.chef_server.data_collector_configured,
[
# module.chef_alb.forward_to_chef_rule_id,
# module.chef_alb.forward_to_automate_rule_id,
module.chef_automate2.a2_url
]
)
ami = data.aws_ami.ubuntu.id
ami_user = var.ami_user
az_subnet_ids = module.vpc.public_subnets
chef_client_version = var.chef_clients["version"]
chef_server_fqdn = module.chef_alb.chef_alb_fqdn
chef_admin = module.test_org_setup.chef_admin
chef_validator = module.test_org_setup.test_chef_validator
instance_count = var.chef_clients["count"]
default_tags = var.default_tags
domain = var.domain
hostnames = var.hostnames
instance = var.instance
instance_keys = var.instance_keys
r53_ttl = var.r53_ttl
ssh_security_group_id = module.security_groups.ssh_security_group_id
unattended_registration_instance_profile = module.chef_unattended_registration.instance_profile
zone_id = data.aws_route53_zone.zone.id
}
module "effortless_clients" {
source = "./effortless_clients"
# server_ready is an inter-module dependency workaround to ensure that the clients don't get created until chef server and alb is created
server_ready = concat(
module.chef_ha.data_collector_configured,
module.chef_server.data_collector_configured,
[
# module.chef_alb.forward_to_chef_rule_id,
# module.chef_alb.forward_to_automate_rule_id,
module.chef_automate2.a2_url
]
)
ami = data.aws_ami.ubuntu.id
ami_user = var.ami_user
az_subnet_ids = module.vpc.public_subnets
origin = var.effortless_clients["origin"]
effortless_audit = var.effortless_clients["effortless_audit"]
effortless_config = var.effortless_clients["effortless_config"]
automate_fqdn = module.chef_alb.automate_alb_fqdn
instance_count = var.effortless_clients["count"]
data_collector_token = module.chef_automate2.data_collector_token
default_tags = var.default_tags
domain = var.domain
hostnames = var.hostnames
instance = var.instance
instance_keys = var.instance_keys
r53_ttl = var.r53_ttl
ssh_security_group_id = module.security_groups.ssh_security_group_id
zone_id = data.aws_route53_zone.zone.id
}