Skip to content

Commit aa93e76

Browse files
KevinSnyderCodesKevin Snyderkayman-mk
authored
feat: add field create_aws_s3_bucket_public_access_block to variable runner_worker_cache (#1105)
## Description Some organizations may disallow configuring block public access settings on individual S3 buckets. For example, the organization may use account level configuration to block public access on all buckets. To support this, we add the field `create_aws_s3_bucket_public_access_block` to the `runner_worker_cache` variable. We add `count` to the `aws_s3_bucket_public_access_block` resource to control its creation and use the `moved` keyword to ensure that existing instances of this resource are not recreated due to this change. ## Migrations required No. Migrations are automatically handled by `moved` keyword. ## Verification Applied this module with the `create_aws_s3_bucket_public_access_block` field set to `false`. The `aws_s3_bucket_public_access_block` resource was not created. All other resources were created as expected. --------- Co-authored-by: Kevin Snyder <[email protected]> Co-authored-by: Matthias Kay <[email protected]>
1 parent c955a5e commit aa93e76

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ module "cache" {
392392
kms_key_id = local.kms_key
393393

394394
name_iam_objects = local.name_iam_objects
395+
396+
create_aws_s3_bucket_public_access_block = var.runner_worker_cache.create_aws_s3_bucket_public_access_block
395397
}
396398

397399
################################################################################

modules/cache/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "build_cache_encry
9595

9696
# block public access to S3 cache bucket
9797
resource "aws_s3_bucket_public_access_block" "build_cache_policy" {
98+
count = var.create_aws_s3_bucket_public_access_block ? 1 : 0
99+
98100
bucket = aws_s3_bucket.build_cache.id
99101

100102
block_public_acls = true

modules/cache/state_migration.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
moved {
2+
from = aws_s3_bucket_public_access_block.build_cache_policy
3+
to = aws_s3_bucket_public_access_block.build_cache_policy[0]
4+
}

modules/cache/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,9 @@ variable "kms_key_id" {
9191
type = string
9292
default = ""
9393
}
94+
95+
variable "create_aws_s3_bucket_public_access_block" {
96+
description = "Enable the creation of the public access block for the cache bucket."
97+
type = bool
98+
default = true
99+
}

variables.tf

+14-12
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ variable "runner_worker_cache" {
413413
bucket = Name of the cache bucket. Requires `create = false`.
414414
bucket_prefix = Prefix for s3 cache bucket name. Requires `create = true`.
415415
create = Boolean used to enable or disable the creation of the cache bucket.
416+
create_aws_s3_bucket_public_access_block = Boolean used to enable or disable the creation of the public access block for the cache bucket. Useful when organizations do not allow the creation of public access blocks on individual buckets (e.g. public access is blocked on all buckets at the organization level).
416417
expiration_days = Number of days before cache objects expire. Requires `create = true`.
417418
include_account_id = Boolean used to include the account id in the cache bucket name. Requires `create = true`.
418419
policy = Policy to use for the cache bucket. Requires `create = false`.
@@ -421,18 +422,19 @@ variable "runner_worker_cache" {
421422
versioning = Boolean used to enable versioning on the cache bucket. Requires `create = true`.
422423
EOT
423424
type = object({
424-
access_log_bucket_id = optional(string, null)
425-
access_log_bucket_prefix = optional(string, null)
426-
authentication_type = optional(string, "iam")
427-
bucket = optional(string, "")
428-
bucket_prefix = optional(string, "")
429-
create = optional(bool, true)
430-
expiration_days = optional(number, 1)
431-
include_account_id = optional(bool, true)
432-
policy = optional(string, "")
433-
random_suffix = optional(bool, false)
434-
shared = optional(bool, false)
435-
versioning = optional(bool, false)
425+
access_log_bucket_id = optional(string, null)
426+
access_log_bucket_prefix = optional(string, null)
427+
authentication_type = optional(string, "iam")
428+
bucket = optional(string, "")
429+
bucket_prefix = optional(string, "")
430+
create = optional(bool, true)
431+
create_aws_s3_bucket_public_access_block = optional(bool, true)
432+
expiration_days = optional(number, 1)
433+
include_account_id = optional(bool, true)
434+
policy = optional(string, "")
435+
random_suffix = optional(bool, false)
436+
shared = optional(bool, false)
437+
versioning = optional(bool, false)
436438
})
437439
default = {}
438440
}

0 commit comments

Comments
 (0)