@@ -46,17 +46,24 @@ data "sysdig_secure_cloud_ingestion_assets" "assets" {
46
46
locals {
47
47
trusted_identity = var. is_gov_cloud_onboarding ? data. sysdig_secure_trusted_cloud_identity . trusted_identity . gov_identity : data. sysdig_secure_trusted_cloud_identity . trusted_identity . identity
48
48
49
- topic_name = split (" :" , var. topic_arn )[5 ]
50
- topic_region = split (" :" , var. topic_arn )[3 ]
49
+
51
50
routing_key = data. sysdig_secure_cloud_ingestion_assets . assets . aws . sns_routing_key
52
51
ingestion_url = data. sysdig_secure_cloud_ingestion_assets . assets . aws . sns_routing_url
53
-
54
- # Determine bucket owner account ID - use provided value or default to current account
52
+
53
+ # Topic variables
54
+ topic_name = split (" :" , var. topic_arn )[5 ]
55
+ topic_region = split (" :" , var. topic_arn )[3 ]
56
+ topic_account_id = split (" :" , var. topic_arn )[4 ]
57
+ is_cross_account_topic = local. topic_account_id != data. aws_caller_identity . current . account_id
58
+
59
+ # Bucket variables
55
60
bucket_account_id = var. bucket_account_id != null ? var. bucket_account_id : data. aws_caller_identity . current . account_id
56
-
57
- # Flag for cross-account bucket access
58
61
is_cross_account = var. bucket_account_id != null && var. bucket_account_id != data. aws_caller_identity . current . account_id
59
62
63
+ # KMS variables
64
+ kms_account_id = split (" :" , var. kms_key_arn )[3 ]
65
+ need_kms_policy = var. bucket_account_id != null && var. bucket_account_id != local. kms_account_id
66
+
60
67
account_id_hash = substr (md5 (local. bucket_account_id ), 0 , 4 )
61
68
role_name = " ${ var . name } -${ random_id . suffix . hex } -${ local . account_id_hash } "
62
69
@@ -183,6 +190,7 @@ resource "aws_sns_topic_policy" "cloudtrail_notifications" {
183
190
}
184
191
185
192
resource "aws_sns_topic_subscription" "cloudtrail_notifications" {
193
+ count = ! local. is_cross_account_topic ? 1 : 0
186
194
topic_arn = var. topic_arn
187
195
provider = aws. sns
188
196
protocol = " https"
@@ -207,9 +215,12 @@ resource "aws_cloudformation_stack_set" "cloudlogs_s3_access" {
207
215
parameters = {
208
216
RoleName = local.role_name
209
217
BucketAccountId = local.bucket_account_id
218
+ TopicAccountId = local.topic_account_id
210
219
SysdigTrustedIdentity = local.trusted_identity
211
220
SysdigExternalId = data.sysdig_secure_tenant_external_id.external_id.external_id
212
221
KmsKeyArn = var.kms_key_arn
222
+ TopicArn = var.topic_arn
223
+ IngestionUrl = local.ingestion_url
213
224
}
214
225
215
226
permission_model = " SERVICE_MANAGED"
@@ -229,7 +240,8 @@ resource "aws_cloudformation_stack_set" "cloudlogs_s3_access" {
229
240
tags = var. tags
230
241
}
231
242
232
- resource "aws_cloudformation_stack_set_instance" "cloudlogs_s3_access" {
243
+ # StackSet instance for the bucket account
244
+ resource "aws_cloudformation_stack_set_instance" "cloudlogs_s3_access_bucket" {
233
245
count = local. is_cross_account ? 1 : 0
234
246
235
247
stack_set_name = aws_cloudformation_stack_set. cloudlogs_s3_access [0 ]. name
@@ -249,6 +261,27 @@ resource "aws_cloudformation_stack_set_instance" "cloudlogs_s3_access" {
249
261
}
250
262
}
251
263
264
+ # StackSet instance for the topic account
265
+ resource "aws_cloudformation_stack_set_instance" "cloudlogs_s3_access_topic" {
266
+ count = local. is_cross_account ? 1 : 0
267
+
268
+ stack_set_name = aws_cloudformation_stack_set. cloudlogs_s3_access [0 ]. name
269
+
270
+ deployment_targets {
271
+ organizational_unit_ids = var. org_units
272
+ account_filter_type = " INTERSECTION"
273
+ accounts = [local . topic_account_id ]
274
+ }
275
+
276
+ region = local. topic_region
277
+
278
+ timeouts {
279
+ create = var. timeout
280
+ update = var. timeout
281
+ delete = var. timeout
282
+ }
283
+ }
284
+
252
285
# -----------------------------------------------------------------------------------------------------------------------------------------
253
286
# Call Sysdig Backend to add the cloud logs integration
254
287
# -----------------------------------------------------------------------------------------------------------------------------------------
@@ -272,6 +305,7 @@ resource "sysdig_secure_cloud_auth_account_component" "aws_cloud_logs" {
272
305
273
306
depends_on = [
274
307
aws_iam_role . cloudlogs_s3_access ,
275
- aws_cloudformation_stack_set_instance . cloudlogs_s3_access
308
+ aws_cloudformation_stack_set_instance . cloudlogs_s3_access_bucket ,
309
+ aws_cloudformation_stack_set_instance . cloudlogs_s3_access_topic
276
310
]
277
311
}
0 commit comments