Skip to content

Commit 6731ac2

Browse files
feat: Add log delivery source organization variables (#322)
Co-authored-by: szubersk <[email protected]>
1 parent bbe0d7b commit 6731ac2

File tree

5 files changed

+119
-62
lines changed

5 files changed

+119
-62
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ No modules.
190190
| <a name="input_acceleration_status"></a> [acceleration\_status](#input\_acceleration\_status) | (Optional) Sets the accelerate configuration of an existing bucket. Can be Enabled or Suspended. | `string` | `null` | no |
191191
| <a name="input_access_log_delivery_policy_source_accounts"></a> [access\_log\_delivery\_policy\_source\_accounts](#input\_access\_log\_delivery\_policy\_source\_accounts) | (Optional) List of AWS Account IDs should be allowed to deliver access logs to this bucket. | `list(string)` | `[]` | no |
192192
| <a name="input_access_log_delivery_policy_source_buckets"></a> [access\_log\_delivery\_policy\_source\_buckets](#input\_access\_log\_delivery\_policy\_source\_buckets) | (Optional) List of S3 bucket ARNs which should be allowed to deliver access logs to this bucket. | `list(string)` | `[]` | no |
193+
| <a name="input_access_log_delivery_policy_source_organizations"></a> [access\_log\_delivery\_policy\_source\_organizations](#input\_access\_log\_delivery\_policy\_source\_organizations) | (Optional) List of AWS Organization IDs should be allowed to deliver access logs to this bucket. | `list(string)` | `[]` | no |
193194
| <a name="input_acl"></a> [acl](#input\_acl) | (Optional) The canned ACL to apply. Conflicts with `grant` | `string` | `null` | no |
194195
| <a name="input_allowed_kms_key_arn"></a> [allowed\_kms\_key\_arn](#input\_allowed\_kms\_key\_arn) | The ARN of KMS key which should be allowed in PutObject | `string` | `null` | no |
195196
| <a name="input_analytics_configuration"></a> [analytics\_configuration](#input\_analytics\_configuration) | Map containing bucket analytics configuration. | `any` | `{}` | no |
@@ -228,6 +229,7 @@ No modules.
228229
| <a name="input_inventory_source_account_id"></a> [inventory\_source\_account\_id](#input\_inventory\_source\_account\_id) | The inventory source account id. | `string` | `null` | no |
229230
| <a name="input_inventory_source_bucket_arn"></a> [inventory\_source\_bucket\_arn](#input\_inventory\_source\_bucket\_arn) | The inventory source bucket ARN. | `string` | `null` | no |
230231
| <a name="input_is_directory_bucket"></a> [is\_directory\_bucket](#input\_is\_directory\_bucket) | If the s3 bucket created is a directory bucket | `bool` | `false` | no |
232+
| <a name="input_lb_log_delivery_policy_source_organizations"></a> [lb\_log\_delivery\_policy\_source\_organizations](#input\_lb\_log\_delivery\_policy\_source\_organizations) | (Optional) List of AWS Organization IDs should be allowed to deliver ALB/NLB logs to this bucket. | `list(string)` | `[]` | no |
231233
| <a name="input_lifecycle_rule"></a> [lifecycle\_rule](#input\_lifecycle\_rule) | List of maps containing configuration of object lifecycle management. | `any` | `[]` | no |
232234
| <a name="input_location_type"></a> [location\_type](#input\_location\_type) | Location type. Valid values: `AvailabilityZone` or `LocalZone` | `string` | `null` | no |
233235
| <a name="input_logging"></a> [logging](#input\_logging) | Map containing access bucket logging configuration. | `any` | `{}` | no |

examples/complete/main.tf

+4-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ module "log_bucket" {
7676
attach_deny_insecure_transport_policy = true
7777
attach_require_latest_tls_policy = true
7878

79-
access_log_delivery_policy_source_accounts = [data.aws_caller_identity.current.account_id]
80-
access_log_delivery_policy_source_buckets = ["arn:aws:s3:::${local.bucket_name}"]
79+
access_log_delivery_policy_source_accounts = [data.aws_caller_identity.current.account_id]
80+
access_log_delivery_policy_source_buckets = ["arn:aws:s3:::${local.bucket_name}"]
81+
access_log_delivery_policy_source_organizations = ["o-123456"]
82+
lb_log_delivery_policy_source_organizations = ["o-123456"]
8183
}
8284

8385
module "cloudfront_log_bucket" {

main.tf

+39
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,16 @@ data "aws_iam_policy_document" "lb_log_delivery" {
688688
variable = "s3:x-amz-acl"
689689
values = ["bucket-owner-full-control"]
690690
}
691+
692+
dynamic "condition" {
693+
for_each = length(var.lb_log_delivery_policy_source_organizations) > 0 ? [true] : []
694+
695+
content {
696+
test = "StringEquals"
697+
variable = "aws:ResourceOrgID"
698+
values = var.lb_log_delivery_policy_source_organizations
699+
}
700+
}
691701
}
692702

693703
statement {
@@ -709,6 +719,15 @@ data "aws_iam_policy_document" "lb_log_delivery" {
709719
aws_s3_bucket.this[0].arn,
710720
]
711721

722+
dynamic "condition" {
723+
for_each = length(var.lb_log_delivery_policy_source_organizations) > 0 ? [true] : []
724+
725+
content {
726+
test = "StringEquals"
727+
variable = "aws:ResourceOrgID"
728+
values = var.lb_log_delivery_policy_source_organizations
729+
}
730+
}
712731
}
713732
}
714733

@@ -754,6 +773,16 @@ data "aws_iam_policy_document" "access_log_delivery" {
754773
}
755774
}
756775

776+
dynamic "condition" {
777+
for_each = length(var.access_log_delivery_policy_source_organizations) > 0 ? [true] : []
778+
779+
content {
780+
test = "StringEquals"
781+
variable = "aws:ResourceOrgID"
782+
values = var.access_log_delivery_policy_source_organizations
783+
}
784+
}
785+
757786
}
758787

759788
statement {
@@ -774,6 +803,16 @@ data "aws_iam_policy_document" "access_log_delivery" {
774803
aws_s3_bucket.this[0].arn,
775804
]
776805

806+
dynamic "condition" {
807+
for_each = length(var.access_log_delivery_policy_source_organizations) > 0 ? [true] : []
808+
809+
content {
810+
test = "StringEquals"
811+
variable = "aws:ResourceOrgID"
812+
values = var.access_log_delivery_policy_source_organizations
813+
}
814+
}
815+
777816
}
778817
}
779818

variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ variable "access_log_delivery_policy_source_accounts" {
172172
default = []
173173
}
174174

175+
variable "access_log_delivery_policy_source_organizations" {
176+
description = "(Optional) List of AWS Organization IDs should be allowed to deliver access logs to this bucket."
177+
type = list(string)
178+
default = []
179+
}
180+
181+
variable "lb_log_delivery_policy_source_organizations" {
182+
description = "(Optional) List of AWS Organization IDs should be allowed to deliver ALB/NLB logs to this bucket."
183+
type = list(string)
184+
default = []
185+
}
186+
175187
variable "grant" {
176188
description = "An ACL policy grant. Conflicts with `acl`"
177189
type = any

0 commit comments

Comments
 (0)