Skip to content

Commit aa2781f

Browse files
Update format and outputs
1 parent 2ca9768 commit aa2781f

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

modules/integrations/cloud-logs/main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ data "aws_caller_identity" "current" {}
2929

3030
data "aws_region" "current" {}
3131

32+
data "aws_partition" "current" {}
33+
3234
data "sysdig_secure_trusted_cloud_identity" "trusted_identity" {
3335
cloud_provider = "aws"
3436
}
@@ -149,7 +151,7 @@ data "aws_iam_policy_document" "cloudlogs_s3_access" {
149151
}
150152

151153
dynamic "statement" {
152-
for_each = var.kms_key_arns != null && !local.is_cross_account ? [1] : []
154+
for_each = var.kms_key_arn != null && !local.is_cross_account ? [1] : []
153155
content {
154156
sid = "CloudlogsKMSDecrypt"
155157

@@ -159,7 +161,7 @@ data "aws_iam_policy_document" "cloudlogs_s3_access" {
159161
"kms:Decrypt"
160162
]
161163

162-
resources = var.kms_key_arns
164+
resources = [var.kms_key_arn]
163165
}
164166
}
165167
}
@@ -209,17 +211,16 @@ resource "aws_cloudformation_stack_set" "bucket_permissions" {
209211
name = local.stackset_name
210212
description = "StackSet to configure S3 bucket and KMS permissions for Sysdig Cloud Logs integration"
211213
template_body = templatefile("${path.module}/stackset_template_body.tpl", {
212-
bucket_name = local.bucket_name
213-
bucket_arn = var.bucket_arn
214-
kms_key_arns = var.kms_key_arns
215-
bucket_account_id = local.bucket_account_id
214+
bucket_arn = var.bucket_arn
215+
kms_key_arn = var.kms_key_arn
216216
})
217217

218218
parameters = {
219219
RoleName = local.role_name
220220
BucketAccountId = local.bucket_account_id
221221
SysdigTrustedIdentity = local.trusted_identity
222222
SysdigExternalId = data.sysdig_secure_tenant_external_id.external_id.external_id
223+
KmsKeyArn = var.kms_key_arn
223224
}
224225

225226
permission_model = "SERVICE_MANAGED"

modules/integrations/cloud-logs/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,15 @@ output "cloud_logs_component_id" {
33
description = "Component identifier of Cloud Logs integration created in Sysdig Backend for Log Ingestion"
44
depends_on = [sysdig_secure_cloud_auth_account_component.aws_cloud_logs]
55
}
6+
7+
output "kms_policy_instructions" {
8+
description = "Instructions for updating KMS key policy when KMS encryption is enabled"
9+
value = (var.kms_key_arn != null) ? templatefile(
10+
"${path.module}/templates/kms_policy_instructions.tpl",
11+
{
12+
role_arn = "arn:${data.aws_partition.current.partition}:iam::${local.bucket_account_id}:role/${local.role_name}"
13+
region = data.aws_region.current.name
14+
bucket_name = local.bucket_name
15+
}
16+
) : ""
17+
}

modules/integrations/cloud-logs/stackset_template_body.tpl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"SysdigExternalId": {
1818
"Type": "String",
1919
"Description": "External ID for secure role assumption by Sysdig"
20+
},
21+
"KmsKeyArn": {
22+
"Type": "String",
23+
"Description": "ARN of the KMS key used for encryption"
2024
}
2125
},
2226
"Conditions": {
@@ -30,12 +34,12 @@
3034
}
3135
]
3236
},
33-
"HasKMSKeys": {
37+
"HasKMSKey": {
3438
"Fn::Not": [
3539
{
3640
"Fn::Equals": [
3741
{
38-
"Fn::Join": ["", ${jsonencode(kms_key_arns != null ? kms_key_arns : [""])}]
42+
"Ref": "KmsKeyArn"
3943
},
4044
""
4145
]
@@ -99,13 +103,13 @@
99103
"${bucket_arn}/*"
100104
]
101105
}
102-
%{ if kms_key_arns != null }
106+
%{ if kms_key_arn != null && kms_key_arn != "" }
103107
,
104108
{
105109
"Sid": "KMSDecryptAccess",
106110
"Effect": "Allow",
107111
"Action": "kms:Decrypt",
108-
"Resource": ${jsonencode(kms_key_arns)}
112+
"Resource": "${kms_key_arn}"
109113
}
110114
%{ endif }
111115
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Sid": "Sysdig-Decrypt",
3+
"Effect": "Allow",
4+
"Principal": {
5+
"AWS": "${role_arn}"
6+
},
7+
"Action": "kms:Decrypt",
8+
"Resource": "*"
9+
}

modules/integrations/cloud-logs/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ variable "org_units" {
101101
description = "List of AWS Organizations organizational unit (OU) IDs in which to create the StackSet instances. Required if is_organizational is true."
102102
default = []
103103
}
104+
105+
variable "kms_key_arn" {
106+
description = "ARN of the KMS key used for encryption. If provided, the role will be granted decrypt permissions."
107+
type = string
108+
default = null
109+
}

outputs.tf

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)