Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 69578e0

Browse files
authored
feat: Support s3 bucket logging for distribution cache bucket (#2430)
* feat: Support s3 bucket logging Allow s3 bucket logging configuration support * adjust bucket prefix regex and validation error
1 parent 5c0744e commit 69578e0

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ In case the setup does not work as intended follow the trace of events:
452452
| <a name="input_runner_architecture"></a> [runner\_architecture](#input\_runner\_architecture) | The platform architecture of the runner instance\_type. | `string` | `"x64"` | no |
453453
| <a name="input_runner_as_root"></a> [runner\_as\_root](#input\_runner\_as\_root) | Run the action runner under the root user. Variable `runner_run_as` will be ignored. | `bool` | `false` | no |
454454
| <a name="input_runner_binaries_s3_sse_configuration"></a> [runner\_binaries\_s3\_sse\_configuration](#input\_runner\_binaries\_s3\_sse\_configuration) | Map containing server-side encryption configuration for runner-binaries S3 bucket. | `any` | `{}` | no |
455+
| <a name="input_runner_binaries_s3_logging_bucket"></a> [runner\_binaries\_s3\_logging\_bucket](#input\_runner\_binaries\_s3\_logging\_bucket) | Bucket for action runner distribution bucket access logging. | `string` | `null` | no |
456+
| <a name="input_runner_binaries_s3_logging_bucket_prefix"></a> [runner\_binaries\_s3\_logging\_bucket\_prefix](#input\_runner\_binaries\_s3\logging\_bucket\_prefix) | Bucket prefix for action runner distribution bucket access logging. | `string` | `null` | no |
455457
| <a name="input_runner_binaries_syncer_lambda_timeout"></a> [runner\_binaries\_syncer\_lambda\_timeout](#input\_runner\_binaries\_syncer\_lambda\_timeout) | Time out of the binaries sync lambda in seconds. | `number` | `300` | no |
456458
| <a name="input_runner_binaries_syncer_lambda_zip"></a> [runner\_binaries\_syncer\_lambda\_zip](#input\_runner\_binaries\_syncer\_lambda\_zip) | File location of the binaries sync lambda zip file. | `string` | `null` | no |
457459
| <a name="input_runner_boot_time_in_minutes"></a> [runner\_boot\_time\_in\_minutes](#input\_runner\_boot\_time\_in\_minutes) | The minimum time for an EC2 runner to boot and register as a runner. | `number` | `5` | no |

Diff for: main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ module "runner_binaries" {
238238
tags = local.tags
239239

240240
distribution_bucket_name = "${var.prefix}-dist-${random_string.random.result}"
241+
s3_logging_bucket = var.runner_binaries_s3_logging_bucket
242+
s3_logging_bucket_prefix = var.runner_binaries_s3_logging_bucket_prefix
241243

242244
runner_os = var.runner_os
243245
runner_architecture = var.runner_architecture

Diff for: modules/runner-binaries-syncer/main.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ resource "aws_s3_bucket_lifecycle_configuration" "bucket-config" {
2828
days = 35
2929
storage_class = "INTELLIGENT_TIERING"
3030
}
31-
32-
3331
}
3432
}
3533

@@ -64,7 +62,13 @@ resource "aws_s3_bucket_public_access_block" "action_dist" {
6462
restrict_public_buckets = true
6563
}
6664

65+
resource "aws_s3_bucket_logging" "action_dist_logging" {
66+
count = var.s3_logging_bucket != null ? 1 : 0
6767

68+
bucket = aws_s3_bucket.action_dist.id
69+
target_bucket = var.s3_logging_bucket
70+
target_prefix = var.s3_logging_bucket_prefix != null ? var.s3_logging_bucket_prefix : var.distribution_bucket_name
71+
}
6872

6973
data "aws_iam_policy_document" "action_dist_sse_policy" {
7074
count = try(var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default, null) != null ? 1 : 0

Diff for: modules/runner-binaries-syncer/variables.tf

+25
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ variable "distribution_bucket_name" {
3636
condition = can(regex("^[a-z0-9-]*$", var.distribution_bucket_name))
3737
}
3838
}
39+
40+
variable "s3_logging_bucket" {
41+
description = "Bucket for action runner distribution bucket access logging."
42+
type = string
43+
default = null
44+
45+
# Make sure the bucket name only contains legal characters
46+
validation {
47+
error_message = "Only lowercase alphanumeric characters and hyphens allowed in the bucket name."
48+
condition = var.s3_logging_bucket == null || can(regex("^[a-z0-9-]*$", var.s3_logging_bucket))
49+
}
50+
}
51+
52+
variable "s3_logging_bucket_prefix" {
53+
description = "Bucket prefix for action runner distribution bucket access logging."
54+
type = string
55+
default = null
56+
57+
# Make sure the bucket name only contains legal characters
58+
validation {
59+
error_message = "Only lowercase alphanumeric characters and hyphens allowed in the bucket name."
60+
condition = var.s3_logging_bucket_prefix == null || can(regex("^[a-z0-9-]*$", var.s3_logging_bucket_prefix))
61+
}
62+
}
63+
3964
variable "lambda_schedule_expression" {
4065
description = "Scheduler expression for action runner binary syncer."
4166
type = string

Diff for: variables.tf

+25
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ variable "runner_binaries_s3_sse_configuration" {
135135
default = {}
136136
}
137137

138+
variable "runner_binaries_s3_logging_bucket" {
139+
description = "Bucket for action runner distribution bucket access logging."
140+
type = string
141+
default = null
142+
143+
# Make sure the bucket name only contains legal characters
144+
validation {
145+
error_message = "Only lowercase alphanumeric characters and hyphens allowed in the bucket name."
146+
condition = var.runner_binaries_s3_logging_bucket == null || can(regex("^[a-z0-9-]*$", var.runner_binaries_s3_logging_bucket))
147+
}
148+
}
149+
150+
variable "runner_binaries_s3_logging_bucket_prefix" {
151+
description = "Bucket prefix for action runner distribution bucket access logging."
152+
type = string
153+
default = null
154+
155+
# Make sure the bucket prefix only contains legal characters
156+
validation {
157+
error_message = "Only alphanumeric characters, hyphens followed by single slashes allowed in the bucket prefix."
158+
condition = var.runner_binaries_s3_logging_bucket_prefix == null || can(regex("^(([a-zA-Z0-9-])+(\\/?))*$", var.runner_binaries_s3_logging_bucket_prefix))
159+
}
160+
}
161+
162+
138163
variable "role_permissions_boundary" {
139164
description = "Permissions boundary that will be added to the created roles."
140165
type = string

0 commit comments

Comments
 (0)