Skip to content

Commit d773dcc

Browse files
add eventsub
1 parent 1290160 commit d773dcc

File tree

8 files changed

+95
-7
lines changed

8 files changed

+95
-7
lines changed

infrastructure/terraform/components/api/glue_crawler_event_crawler.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ resource "aws_glue_crawler" "event_crawler" {
88
s3_target {
99
path = "s3://${local.csi_global}-eventcache/"
1010
}
11+
12+
s3_target {
13+
path = "s3://${local.csi_global}-eventsubeventcache/"
14+
}
1115
recrawl_policy {
1216
recrawl_behavior = "CRAWL_EVERYTHING"
1317
}

infrastructure/terraform/components/api/iam_role_glue.tf

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,34 @@ data "aws_iam_policy_document" "glue_service_policy" {
3838
resources = ["arn:aws:logs:*:*:*"]
3939
}
4040

41+
statement {
42+
sid = "AllowListBucketAndGetLocation"
43+
effect = "Allow"
44+
45+
actions = [
46+
"s3:ListBucket",
47+
"s3:GetBucketLocation"
48+
]
49+
50+
resources = [
51+
"arn:aws:s3:::${local.csi_global}-eventcache",
52+
"arn:aws:s3:::${local.csi_global}-eventsubeventcache"
53+
]
54+
}
4155
statement {
4256
sid = "AllowS3Access"
4357
effect = "Allow"
4458

4559
actions = [
4660
"s3:GetObject",
61+
"s3:GetObjectVersion",
4762
"s3:PutObject",
48-
"s3:ListBucket",
49-
"s3:GetBucketLocation",
5063
"s3:DeleteObject"
5164
]
52-
resources = ["arn:aws:s3:::${local.csi}-glue-bucket/*",
53-
"arn:aws:s3:::${local.csi_global}-eventcache/*"]
65+
resources = [
66+
"arn:aws:s3:::${local.csi_global}-eventcache/*",
67+
"arn:aws:s3:::${local.csi_global}-eventsubeventcache/*"
68+
]
5469
}
5570
statement {
5671
sid = "GlueCatalogAccess"
@@ -65,7 +80,8 @@ data "aws_iam_policy_document" "glue_service_policy" {
6580
"glue:CreatePartition",
6681
"glue:BatchCreatePartition",
6782
"glue:GetPartition",
68-
"glue:BatchGetPartition"
83+
"glue:BatchGetPartition",
84+
"glue:UpdatePartition"
6985
]
7086
resources = ["*"]
7187
}

infrastructure/terraform/components/api/modules_eventsub.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module "eventsub" {
1212

1313
default_tags = local.default_tags
1414

15+
glue_role_arn = aws_iam_role.glue_role.arn
16+
1517
kms_key_arn = module.kms.key_arn
1618
log_retention_in_days = var.log_retention_in_days
1719
log_level = "INFO"
@@ -22,7 +24,7 @@ module "eventsub" {
2224
sns_success_logging_sample_percent = var.sns_success_logging_sample_percent
2325

2426
event_cache_expiry_days = 30
25-
enable_event_cache = var.enable_event_cache
27+
enable_event_cache = var.enable_event_cache
2628

2729
shared_infra_account_id = var.shared_infra_account_id
2830
}

infrastructure/terraform/components/api/s3_bucket_policy_eventcache.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "aws_s3_bucket_policy" "eventcache" {
33
bucket = local.event_cache_bucket_name
44
policy = data.aws_iam_policy_document.eventcache[0].json
55

6-
depends_on = [ module.eventpub ]
6+
depends_on = [module.eventpub]
77
}
88

99
data "aws_iam_policy_document" "eventcache" {

infrastructure/terraform/modules/eventsub/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
| <a name="input_event_cache_buffer_interval"></a> [event\_cache\_buffer\_interval](#input\_event\_cache\_buffer\_interval) | The buffer interval for data firehose | `number` | `500` | no |
2222
| <a name="input_event_cache_expiry_days"></a> [event\_cache\_expiry\_days](#input\_event\_cache\_expiry\_days) | s3 archiving expiry in days | `number` | `30` | no |
2323
| <a name="input_force_destroy"></a> [force\_destroy](#input\_force\_destroy) | When enabled will force destroy event-cache S3 bucket | `bool` | `false` | no |
24+
| <a name="input_glue_role_arn"></a> [glue\_role\_arn](#input\_glue\_role\_arn) | ARN of the Glue execution role from the parent | `string` | n/a | yes |
2425
| <a name="input_group"></a> [group](#input\_group) | The name of the tfscaffold group | `string` | `null` | no |
2526
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | KMS key arn to use for this function | `string` | n/a | yes |
2627
| <a name="input_log_level"></a> [log\_level](#input\_log\_level) | The log level to be used in lambda functions within the component. Any log with a lower severity than the configured value will not be logged: https://docs.python.org/3/library/logging.html#levels | `string` | `"WARN"` | no |

infrastructure/terraform/modules/eventsub/locals.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ locals {
1212
"_",
1313
"",
1414
)
15+
csi_global = replace(
16+
format(
17+
"%s-%s-%s-%s-%s",
18+
var.project,
19+
var.aws_account_id,
20+
var.region,
21+
var.environment,
22+
var.component,
23+
),
24+
"_",
25+
"",
26+
)
1527
default_tags = merge(
1628
var.default_tags,
1729
{
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
resource "aws_s3_bucket_policy" "eventcache" {
2+
bucket = module.s3bucket_event_cache[0].bucket
3+
policy = data.aws_iam_policy_document.eventcache.json
4+
count = var.enable_event_cache ? 1 : 0
5+
}
6+
7+
data "aws_iam_policy_document" "eventcache" {
8+
statement {
9+
sid = "AllowGlueListBucketAndGetLocation"
10+
effect = "Allow"
11+
12+
principals {
13+
type = "AWS"
14+
identifiers = [var.glue_role_arn]
15+
}
16+
17+
actions = [
18+
"s3:ListBucket",
19+
"s3:GetBucketLocation"
20+
]
21+
22+
resources = [
23+
"arn:aws:s3:::${local.csi_global}-eventsubeventcache"
24+
]
25+
}
26+
27+
# Object-level permissions: Get/Put/Delete objects
28+
statement {
29+
sid = "AllowGlueObjectAccess"
30+
effect = "Allow"
31+
32+
principals {
33+
type = "AWS"
34+
identifiers = [var.glue_role_arn]
35+
}
36+
37+
actions = [
38+
"s3:GetObject",
39+
"s3:GetObjectVersion",
40+
"s3:PutObject",
41+
"s3:DeleteObject"
42+
]
43+
44+
resources = [
45+
"arn:aws:s3:::${local.csi_global}-eventsubeventcache/*"
46+
]
47+
}
48+
}

infrastructure/terraform/modules/eventsub/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,8 @@ variable "shared_infra_account_id" {
114114
description = "The AWS Account ID of the shared infrastructure account"
115115
default = "000000000000"
116116
}
117+
118+
variable "glue_role_arn" {
119+
type = string
120+
description = "ARN of the Glue execution role from the parent"
121+
}

0 commit comments

Comments
 (0)