Skip to content

Commit 8f99c17

Browse files
committed
DL-167 grant data and insight ecs role to write to datahub config bucket
1 parent fa2544b commit 8f99c17

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

terraform/core/05-departments.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ module "department_data_and_insight" {
154154
mwaa_key_arn = aws_kms_key.mwaa_key.arn
155155
user_uploads_bucket = module.user_uploads
156156
cloudtrail_bucket = module.cloudtrail_storage
157+
datahub_config_bucket = module.datahub_config
157158
additional_glue_database_access = {
158159
read_only = []
159160
read_write = ["arcus_archive", "metastore"]

terraform/modules/department/02-inputs-optional.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ variable "cloudtrail_bucket" {
6868
default = null
6969
}
7070

71+
variable "datahub_config_bucket" {
72+
description = "DataHub config S3 bucket"
73+
type = object({
74+
bucket_id = string
75+
bucket_arn = string
76+
kms_key_arn = string
77+
})
78+
default = null
79+
}
80+
7181
variable "additional_glue_database_access" {
7282
description = <<EOF
7383
Additional Glue database access to grant to the department.

terraform/modules/department/50-aws-iam-policies.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,3 +1425,45 @@ resource "aws_iam_policy" "cloudtrail_access_policy" {
14251425
description = "Allows ${local.department_identifier} department read-only access to CloudTrail bucket"
14261426
policy = data.aws_iam_policy_document.cloudtrail_access[0].json
14271427
}
1428+
1429+
// Write access to DataHub config bucket for Data and Insight department only
1430+
data "aws_iam_policy_document" "datahub_config_access" {
1431+
count = local.department_identifier == "data-and-insight" && var.datahub_config_bucket != null ? 1 : 0
1432+
1433+
statement {
1434+
sid = "DataHubConfigKmsAccess"
1435+
effect = "Allow"
1436+
actions = [
1437+
"kms:Encrypt",
1438+
"kms:Decrypt",
1439+
"kms:ReEncrypt*",
1440+
"kms:GenerateDataKey*",
1441+
"kms:DescribeKey"
1442+
]
1443+
resources = [var.datahub_config_bucket.kms_key_arn]
1444+
}
1445+
1446+
statement {
1447+
sid = "DataHubConfigS3WriteAccess"
1448+
effect = "Allow"
1449+
actions = [
1450+
"s3:GetObject",
1451+
"s3:GetObjectVersion",
1452+
"s3:ListBucket",
1453+
"s3:PutObject",
1454+
"s3:PutObjectAcl",
1455+
"s3:DeleteObject"
1456+
]
1457+
resources = [
1458+
var.datahub_config_bucket.bucket_arn,
1459+
"${var.datahub_config_bucket.bucket_arn}/*"
1460+
]
1461+
}
1462+
}
1463+
1464+
resource "aws_iam_policy" "datahub_config_access_policy" {
1465+
count = local.department_identifier == "data-and-insight" && var.datahub_config_bucket != null ? 1 : 0
1466+
name = lower("${var.identifier_prefix}-${local.department_identifier}-datahub-config-access-policy")
1467+
description = "Allows ${local.department_identifier} department write access to DataHub config bucket"
1468+
policy = data.aws_iam_policy_document.datahub_config_access[0].json
1469+
}

terraform/modules/department/50-aws-iam-roles.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,9 @@ resource "aws_iam_role_policy_attachment" "ecs_parameter_store_access" {
175175
role = aws_iam_role.department_ecs_role.name
176176
policy_arn = aws_iam_policy.parameter_store_read_only.arn
177177
}
178+
179+
resource "aws_iam_role_policy_attachment" "datahub_config_access_attachment" {
180+
count = local.department_identifier == "data-and-insight" && var.datahub_config_bucket != null ? 1 : 0
181+
role = aws_iam_role.department_ecs_role.name
182+
policy_arn = aws_iam_policy.datahub_config_access_policy[0].arn
183+
}

0 commit comments

Comments
 (0)