Skip to content

Commit

Permalink
add bucket_owner
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jan 18, 2022
1 parent 6f087e3 commit b9799cf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ Provides standard and t26 S3 bucket construction.
* v2.3.0 -- 20211117
- add submodule kms_key to be able to create a key, and then use it for later bucket
- allow kms_key_arn to passed in for standard and title26 buckets

* v2.4.0 -- 20220118
- add bucket_owner controls (default BucketOwnerPreferred)
17 changes: 17 additions & 0 deletions common/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ locals {
"variable" : "aws:sourceVpce"
"values" : var.allowed_endpoints
}
condition_bucket_owner = {
"test" : "StringEquals"
"variable" : "s3:x-amz-acl"
"values" : var.bucket_owner == "BucketOwnerPreferred" ? "bucket-owner-full-control" : ""
}
s3_bucket_conditions_list = list(local.condition_allowed_cidr, local.condition_allowed_endpoints)
s3_bucket_conditions = [for x in local.s3_bucket_conditions_list : x if length(x.values) > 0]

Expand Down Expand Up @@ -197,3 +202,15 @@ data "aws_iam_policy_document" "bucket_policy_combined" {
]
}

#---
# set ownership controls
# see documentation:
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls
#
resource "aws_s3_bucket_ownership_controls" "this" {
bucket = aws_s3_bucket.this.id

rule {
object_ownership = var.bucket_owner
}
}
6 changes: 6 additions & 0 deletions common/variables.s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ variable "require_explicit_encryption" {
# TBD
# variable "kms_policy_read_arns" { }
# variable "kms_policy_write_arns" { }

variable "bucket_owner" {
description = "One of BucketOwnerPreferred, ObjectWriter, or BucketOwnerEnforced. See S3 Documentation for more information (default: BucketOwnerPreferred, requires bucket-owner-full-control option when uploading"
type = string
default = "BucketOwnerPreferred"
}
13 changes: 13 additions & 0 deletions common/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.66.0"
}
null = {
source = "hashicorp/null"
version = ">= 3.1.0"
}
}
# required_version = ">= 0.13"
}

0 comments on commit b9799cf

Please sign in to comment.