This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
generated from dwp/dataworks-repo-template-terraform
-
Notifications
You must be signed in to change notification settings - Fork 3
/
terraform.tf.j2
326 lines (275 loc) · 11.3 KB
/
terraform.tf.j2
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
terraform {
required_version = "{{terraform.terraform_version}}"
backend "s3" {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/dataworks-aws-data-egress.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
required_providers {
aws = {
version = "4.53.0"
}
}
}
// Get AWS Account ID for credentials in use
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_availability_zones" "available" {}
data "aws_ec2_managed_prefix_list" "list" {
name = "dwp-*-aws-cidrs-*"
}
data "aws_secretsmanager_secret_version" "terraform_secrets" {
provider = aws.management_dns
secret_id = "/concourse/dataworks/terraform"
}
locals {
name = "dataworks-aws-data-egress"
environment = terraform.workspace == "default" ? "development" : terraform.workspace
# Configured as per Tagging doc requirements https://engineering.dwp.gov.uk/policies/hcs-cloud-hosting-policies/resource-identification-tagging/
# Also required as per Tenable documentation https://engineering.dwp.gov.uk/products/gold-images/agents/tenable/
hcs_environment = {
development = "Dev"
qa = "Test"
integration = "Stage"
preprod = "Stage"
production = "Production"
management = "SP_Tooling"
management-dev = "DT_Tooling"
}
account = {
{%- for key, value in accounts.items() %}
{{key}} = "{{value}}"
{%- endfor %}
}
tags = {
Name = "dataworks-aws-data-egress"
DWX_Environment = local.environment
DWX_Application = "dataworks-aws-data-egress"
Persistence = "Ignore"
AutoShutdown = "False"
}
common_tags = {
{%- for key, value in common_tags.items() %}
{{key}} = "{{value}}"
{%- endfor %}
DWX_Environment = local.environment
DWX_Application = local.name
}
cidr_block = {
{%- for environment, ranges in cidr_block.items() %}
{{ environment }} = {
{%- for key, value in ranges.items() %}
{{ key }} = "{{ value }}"{% endfor %}
} {%- endfor %}
}
data_egress_ecs_friendly_name = "data-egress-ecs-cluster"
cluster_name = replace(local.data_egress_ecs_friendly_name, "-ecs-cluster", "")
cw_agent_log_group_name_data_egress_ecs = "/app/${local.data_egress_ecs_friendly_name}"
data_egress_friendly_name = "data-egress-cluster"
opsmi = {
{%- for environment, ranges in opsmi.items() %}
{{ environment }} = {
{%- for key, value in ranges.items() %}
{{ key }} = "{{ value }}"{% endfor %}
} {%- endfor %}
}
oneservice = {
{%- for environment, ranges in oneservice.items() %}
{{ environment }} = {
{%- for key, value in ranges.items() %}
{{ key }} = "{{ value }}"{% endfor %}
} {%- endfor %}
}
data_egress = {
{%- for environment, ranges in data_egress.items() %}
{{ environment }} = {
{%- for key, value in ranges.items() %}
{{ key }} = "{{ value }}"{% endfor %}
} {%- endfor %}
}
pdm_rtg = {
{%- for environment,contents in pdm_rtg.items() %}
{{ environment }} = {
{%- for key, value in contents.items() %}
{{ key }} = "{{ value }}"{% endfor %}
} {%- endfor %}
}
htme_incr_rtg = {
{%- for environment,contents in htme_incr_rtg.items() %}
{{ environment }} = {
{%- for key, value in contents.items() %}
{{ key }} = "{{ value }}"{% endfor %}
} {%- endfor %}
}
htme_full_rtg = {
{%- for environment,contents in htme_full_rtg.items() %}
{{ environment }} = {
{%- for key, value in contents.items() %}
{{ key }} = "{{ value }}"{% endfor %}
} {%- endfor %}
}
}
data "terraform_remote_state" "common" {
backend = "s3"
workspace = terraform.workspace
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/common.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "terraform_remote_state" "certificate_authority" {
backend = "s3"
workspace = terraform.workspace
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/aws-certificate-authority.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "terraform_remote_state" "crypto" {
backend = "s3"
workspace = local.crypto_workspace[local.management_account[local.environment]]
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/aws-crypto.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "terraform_remote_state" "aws_sdx" {
backend = "s3"
workspace = terraform.workspace
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/aws-sdx.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "terraform_remote_state" "mgmt_ca" {
backend = "s3"
workspace = local.management_account[local.environment]
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/aws-certificate-authority.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "terraform_remote_state" "management" {
backend = "s3"
workspace = local.management_infra_account[local.environment]
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/management.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "terraform_remote_state" "snapshot_sender" {
backend = "s3"
workspace = terraform.workspace
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/aws-snapshot-sender.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "terraform_remote_state" "internal_compute" {
backend = "s3"
workspace = terraform.workspace
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/aws-internal-compute.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "terraform_remote_state" "data_ingress" {
backend = "s3"
workspace = terraform.workspace
config = {
bucket = "{{terraform.state_file_bucket}}"
key = "terraform/dataworks/dataworks-aws-data-ingress.tfstate"
region = "{{terraform.state_file_region}}"
encrypt = true
kms_key_id = "arn:aws:kms:{{terraform.state_file_region}}:{{terraform.state_file_account}}:key/{{terraform.state_file_kms_key}}"
dynamodb_table = "remote_state_locks"
}
}
data "aws_secretsmanager_secret" "rtg_secret_full_collections" {
name = local.secret_name_for_rtg_full_collections
}
data "aws_secretsmanager_secret_version" "rtg_secret_full_collections" {
secret_id = data.aws_secretsmanager_secret.rtg_secret_full_collections.id
}
data "aws_secretsmanager_secret" "rtg_secret_incremental_collections" {
name = local.secret_name_for_rtg_incremental_collections
}
data "aws_secretsmanager_secret_version" "rtg_secret_incremental_collections" {
secret_id = data.aws_secretsmanager_secret.rtg_secret_incremental_collections.id
}
data "aws_secretsmanager_secret" "rtg_secret_pdm_queries" {
name = local.secret_name_for_pdm_queries
}
data "aws_secretsmanager_secret_version" "rtg_secret_pdm_queries" {
secret_id = data.aws_secretsmanager_secret.rtg_secret_pdm_queries.id
}
data "aws_secretsmanager_secret" "secret_for_ris_collections" {
name = local.secret_name_for_ris_collections
}
data "aws_secretsmanager_secret_version" "secret_for_ris_collections" {
secret_id = data.aws_secretsmanager_secret.secret_for_ris_collections.id
}
provider "aws" {
region = var.region
default_tags {
tags = {
Application = "DataWorks" # As per our definition on ServiceNow
Function = "Data and Analytics" # As per our definition on ServiceNow
Environment = local.hcs_environment[local.environment] # Set up locals as per Tagging doc requirements https://engineering.dwp.gov.uk/policies/hcs-cloud-hosting-policies/resource-identification-tagging/
Business-Project = "PRJ0022507" # This seems to replace costcode as per the doc https://engineering.dwp.gov.uk/policies/hcs-cloud-hosting-policies/resource-identification-tagging/
}
}
assume_role {
role_arn = "arn:aws:iam::${lookup(local.account, local.environment)}:role/${var.assume_role}"
}
}
provider "aws" {
alias = "management_dns"
region = var.region
default_tags {
tags = {
Application = "DataWorks" # As per our definition on ServiceNow
Function = "Data and Analytics" # As per our definition on ServiceNow
Environment = local.hcs_environment[local.environment] # Set up locals as per Tagging doc requirements https://engineering.dwp.gov.uk/policies/hcs-cloud-hosting-policies/resource-identification-tagging/
Business-Project = "PRJ0022507" # This seems to replace costcode as per the doc https://engineering.dwp.gov.uk/policies/hcs-cloud-hosting-policies/resource-identification-tagging/
}
}
assume_role {
role_arn = "arn:aws:iam::${local.account[local.management_account[local.environment]]}:role/${var.assume_role}"
}
}