Skip to content

Commit c5dc333

Browse files
Remove CloudTrail from monitoring (managed in org/) (#15)
Fixes the apply failure from PR #13. CloudTrail resources are in terraform/org/ — the duplicate in monitoring caused a DeleteTrail error blocked by the permission boundary.
1 parent 5ecc331 commit c5dc333

2 files changed

Lines changed: 1 addition & 114 deletions

File tree

scripts/post-review-comment.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,16 @@
33
#
44
# Usage: post-review-comment.sh
55
#
6-
# Reads review-result.json and review-output.txt from current directory.
6+
# Reads review-output.txt from current directory.
77
# Env: GH_TOKEN (or gh auth), GITHUB_REPOSITORY, PR_NUMBER
88

99
set -e
1010

11-
RISK=$(jq -r '.risk // "FAILED"' review-result.json 2>/dev/null || echo "FAILED")
1211
REVIEW=$(cat review-output.txt 2>/dev/null || echo "LLM review output not available.")
1312

14-
case "$RISK" in
15-
LOW) EMOJI="🟢" ;;
16-
MEDIUM) EMOJI="🟡" ;;
17-
HIGH) EMOJI="🔴" ;;
18-
*) EMOJI="" ;;
19-
esac
20-
2113
cat > /tmp/review-comment.md <<EOF
2214
## LLM Plan Review
2315
24-
**Risk: ${EMOJI} ${RISK}**
25-
2616
${REVIEW}
2717
EOF
2818

terraform/platform/monitoring/main.tf

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,3 @@
1-
################################################################################
2-
# CloudTrail — required for EventBridge to receive API call events
3-
#
4-
# Without a trail, EventBridge rules matching "AWS API Call via CloudTrail"
5-
# never fire. This is the single trail (free tier) with management events only.
6-
################################################################################
7-
8-
resource "aws_s3_bucket" "cloudtrail" {
9-
bucket = "${var.project}-cloudtrail-${var.aws_account_id}"
10-
11-
tags = {
12-
Name = "${var.project}-cloudtrail"
13-
}
14-
}
15-
16-
resource "aws_s3_bucket_server_side_encryption_configuration" "cloudtrail" {
17-
bucket = aws_s3_bucket.cloudtrail.id
18-
19-
rule {
20-
apply_server_side_encryption_by_default {
21-
sse_algorithm = "aws:kms"
22-
}
23-
}
24-
}
25-
26-
resource "aws_s3_bucket_public_access_block" "cloudtrail" {
27-
bucket = aws_s3_bucket.cloudtrail.id
28-
29-
block_public_acls = true
30-
block_public_policy = true
31-
ignore_public_acls = true
32-
restrict_public_buckets = true
33-
}
34-
35-
resource "aws_s3_bucket_lifecycle_configuration" "cloudtrail" {
36-
bucket = aws_s3_bucket.cloudtrail.id
37-
38-
rule {
39-
id = "expire-old-logs"
40-
status = "Enabled"
41-
42-
expiration {
43-
days = 90
44-
}
45-
}
46-
}
47-
48-
resource "aws_s3_bucket_policy" "cloudtrail" {
49-
bucket = aws_s3_bucket.cloudtrail.id
50-
51-
policy = jsonencode({
52-
Version = "2012-10-17"
53-
Statement = [
54-
{
55-
Sid = "AWSCloudTrailAclCheck"
56-
Effect = "Allow"
57-
Principal = { Service = "cloudtrail.amazonaws.com" }
58-
Action = "s3:GetBucketAcl"
59-
Resource = aws_s3_bucket.cloudtrail.arn
60-
Condition = {
61-
StringEquals = {
62-
"aws:SourceArn" = "arn:aws:cloudtrail:${var.region}:${var.aws_account_id}:trail/${var.project}-trail"
63-
}
64-
}
65-
},
66-
{
67-
Sid = "AWSCloudTrailWrite"
68-
Effect = "Allow"
69-
Principal = { Service = "cloudtrail.amazonaws.com" }
70-
Action = "s3:PutObject"
71-
Resource = "${aws_s3_bucket.cloudtrail.arn}/AWSLogs/${var.aws_account_id}/*"
72-
Condition = {
73-
StringEquals = {
74-
"s3:x-amz-acl" = "bucket-owner-full-control"
75-
"aws:SourceArn" = "arn:aws:cloudtrail:${var.region}:${var.aws_account_id}:trail/${var.project}-trail"
76-
}
77-
}
78-
}
79-
]
80-
})
81-
}
82-
83-
resource "aws_cloudtrail" "main" {
84-
name = "${var.project}-trail"
85-
s3_bucket_name = aws_s3_bucket.cloudtrail.id
86-
is_multi_region_trail = true
87-
enable_log_file_validation = true
88-
89-
# Send events to EventBridge (required for our rules to fire)
90-
# This is enabled by default for management events when a trail exists,
91-
# but being explicit about it
92-
event_selector {
93-
read_write_type = "All"
94-
include_management_events = true
95-
}
96-
97-
depends_on = [aws_s3_bucket_policy.cloudtrail]
98-
99-
tags = {
100-
Name = "${var.project}-trail"
101-
}
102-
}
103-
1041
################################################################################
1052
# SNS Topics for Alerts
1063
################################################################################

0 commit comments

Comments
 (0)