Skip to content

Commit a1456da

Browse files
authored
feat: Support passing KMS key to bucket encryption configuration (#317)
* feat: pass KMS key to bucket encryption
1 parent 4defe29 commit a1456da

File tree

11 files changed

+238
-193
lines changed

11 files changed

+238
-193
lines changed

.github/workflows/validate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ on:
1010

1111
jobs:
1212
validate-tf:
13-
uses: trussworks/shared-actions/.github/workflows/validate-tf.yml@main
13+
uses: trussworks/shared-actions/.github/workflows/validate-tf.yml@3cab03ab95045711da37ad6d63a93c666fc22398 # v0.0.2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.terraform
3+
.terraform.lock.hcl
34
terraform.tfstate
45
terraform.tfstate.backup
56
terraform.tfstate.*.backup
6-
.envrc.local
7+
.envrc*

.golangci.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.markdownlintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"first-line-h1": false,
55
"line_length": false,
66
"no-multiple-blanks": false,
7-
"no-inline-html": false
7+
"no-inline-html": false,
8+
"no-alt-text": false
89
}

.pre-commit-config.yaml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-json
66
- id: check-merge-conflict
@@ -14,27 +14,17 @@ repos:
1414
- id: end-of-file-fixer
1515
- id: mixed-line-ending
1616

17-
- repo: https://github.com/executablebooks/mdformat
18-
rev: 0.7.16
19-
hooks:
20-
- id: mdformat
21-
additional_dependencies:
22-
- mdformat-gfm
23-
- mdformat-toc
24-
# mdformat fights with terraform_docs
25-
exclude: README.m(ark)?d(own)?
26-
2717
- repo: https://github.com/igorshubovych/markdownlint-cli
28-
rev: v0.33.0
18+
rev: v0.43.0
2919
hooks:
3020
- id: markdownlint
3121

32-
- repo: https://github.com/detailyang/pre-commit-shell
33-
rev: 1.0.5
22+
- repo: https://github.com/terraform-docs/terraform-docs
23+
rev: "v0.19.0"
3424
hooks:
35-
- id: shell-lint
25+
- id: terraform-docs-system
3626

3727
- repo: https://github.com/antonbabenko/pre-commit-terraform
38-
rev: v1.77.1
28+
rev: v1.96.3
3929
hooks:
4030
- id: terraform_fmt

.terraform-docs.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1+
version: ">= 0.19.0, < 1.0.0"
2+
13
settings:
24
html: false
35
anchor: false
6+
escape: false
7+
lockfile: false
8+
hide-empty: true
49
formatter: "markdown table"
10+
11+
sort:
12+
enabled: true
13+
by: required
14+
15+
sections:
16+
show:
17+
- requirements
18+
- providers
19+
- modules
20+
- data-sources
21+
- resources
22+
- inputs
23+
- outputs
24+
25+
recursive:
26+
enabled: false
27+
include-main: false
28+
29+
output:
30+
file: README.md
31+
mode: inject
32+
template: |-
33+
<!-- BEGIN_TF_DOCS -->
34+
{{ .Content }}
35+
<!-- END_TF_DOCS -->

README.md

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ module "aws_logs" {
9494
|------|---------|
9595
| aws | >= 3.75.0 |
9696

97-
## Modules
98-
99-
No modules.
100-
10197
## Resources
10298

10399
| Name | Type |
@@ -121,54 +117,56 @@ No modules.
121117

122118
| Name | Description | Type | Default | Required |
123119
|------|-------------|------|---------|:--------:|
124-
| alb\_account | Account for ALB logs. By default limits to the current account. | `string` | `""` | no |
125-
| alb\_logs\_prefixes | S3 key prefixes for ALB logs. | `list(string)` | ```[ "alb" ]``` | no |
126-
| allow\_alb | Allow ALB service to log to bucket. | `bool` | `false` | no |
127-
| allow\_cloudtrail | Allow Cloudtrail service to log to bucket. | `bool` | `false` | no |
128-
| allow\_cloudwatch | Allow Cloudwatch service to export logs to bucket. | `bool` | `false` | no |
129-
| allow\_config | Allow Config service to log to bucket. | `bool` | `false` | no |
130-
| allow\_elb | Allow ELB service to log to bucket. | `bool` | `false` | no |
131-
| allow\_nlb | Allow NLB service to log to bucket. | `bool` | `false` | no |
132-
| allow\_redshift | Allow Redshift service to log to bucket. | `bool` | `false` | no |
133-
| allow\_s3 | Allow S3 service to log to bucket. | `bool` | `false` | no |
134-
| cloudtrail\_accounts | List of accounts for CloudTrail logs. By default limits to the current account. | `list(string)` | `[]` | no |
135-
| cloudtrail\_logs\_prefix | S3 prefix for CloudTrail logs. | `string` | `"cloudtrail"` | no |
136-
| cloudtrail\_org\_id | AWS Organization ID for CloudTrail. | `string` | `""` | no |
137-
| cloudwatch\_logs\_prefix | S3 prefix for CloudWatch log exports. | `string` | `"cloudwatch"` | no |
138-
| config\_accounts | List of accounts for Config logs. By default limits to the current account. | `list(string)` | `[]` | no |
139-
| config\_logs\_prefix | S3 prefix for AWS Config logs. | `string` | `"config"` | no |
140-
| control\_object\_ownership | Whether to manage S3 Bucket Ownership Controls on this bucket. | `bool` | `true` | no |
141-
| create\_public\_access\_block | Whether to create a public\_access\_block restricting public access to the bucket. | `bool` | `true` | no |
142-
| default\_allow | Whether all services included in this module should be allowed to write to the bucket by default. Alternatively select individual services. It's recommended to use the default bucket ACL of log-delivery-write. | `bool` | `true` | no |
143-
| elb\_accounts | List of accounts for ELB logs. By default limits to the current account. | `list(string)` | `[]` | no |
144-
| elb\_logs\_prefix | S3 prefix for ELB logs. | `string` | `"elb"` | no |
145-
| enable\_mfa\_delete | A bool that requires MFA to delete the log bucket. | `bool` | `false` | no |
146-
| enable\_s3\_log\_bucket\_lifecycle\_rule | Whether the lifecycle rule for the log bucket is enabled. | `bool` | `true` | no |
147-
| force\_destroy | A bool that indicates all objects (including any locked objects) should be deleted from the bucket so the bucket can be destroyed without error. | `bool` | `false` | no |
148-
| logging\_target\_bucket | S3 Bucket to send S3 logs to. Disables logging if omitted. | `string` | `""` | no |
149-
| logging\_target\_prefix | Prefix for logs going into the log\_s3\_bucket. | `string` | `"s3/"` | no |
150-
| nlb\_account | Account for NLB logs. By default limits to the current account. | `string` | `""` | no |
151-
| nlb\_logs\_prefixes | S3 key prefixes for NLB logs. | `list(string)` | ```[ "nlb" ]``` | no |
152-
| noncurrent\_version\_retention | Number of days to retain non-current versions of objects if versioning is enabled. | `string` | `30` | no |
153-
| object\_ownership | Object ownership. Valid values: BucketOwnerEnforced, BucketOwnerPreferred or ObjectWriter. | `string` | `"BucketOwnerEnforced"` | no |
154-
| redshift\_logs\_prefix | S3 prefix for RedShift logs. | `string` | `"redshift"` | no |
155-
| s3\_bucket\_acl | Set bucket ACL per [AWS S3 Canned ACL](<https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl>) list. | `string` | `null` | no |
156-
| s3\_bucket\_name | S3 bucket to store AWS logs in. | `string` | n/a | yes |
157-
| s3\_log\_bucket\_retention | Number of days to keep AWS logs around. | `string` | `90` | no |
158-
| s3\_logs\_prefix | S3 prefix for S3 access logs. | `string` | `"s3"` | no |
120+
| s3_bucket_name | S3 bucket to store AWS logs in. | `string` | n/a | yes |
121+
| alb_account | Account for ALB logs. By default limits to the current account. | `string` | `""` | no |
122+
| alb_logs_prefixes | S3 key prefixes for ALB logs. | `list(string)` | ```[ "alb" ]``` | no |
123+
| allow_alb | Allow ALB service to log to bucket. | `bool` | `false` | no |
124+
| allow_cloudtrail | Allow Cloudtrail service to log to bucket. | `bool` | `false` | no |
125+
| allow_cloudwatch | Allow Cloudwatch service to export logs to bucket. | `bool` | `false` | no |
126+
| allow_config | Allow Config service to log to bucket. | `bool` | `false` | no |
127+
| allow_elb | Allow ELB service to log to bucket. | `bool` | `false` | no |
128+
| allow_nlb | Allow NLB service to log to bucket. | `bool` | `false` | no |
129+
| allow_redshift | Allow Redshift service to log to bucket. | `bool` | `false` | no |
130+
| allow_s3 | Allow S3 service to log to bucket. | `bool` | `false` | no |
131+
| bucket_key_enabled | Whether or not to use Amazon S3 Bucket Keys for SSE-KMS. | `bool` | `false` | no |
132+
| cloudtrail_accounts | List of accounts for CloudTrail logs. By default limits to the current account. | `list(string)` | `[]` | no |
133+
| cloudtrail_logs_prefix | S3 prefix for CloudTrail logs. | `string` | `"cloudtrail"` | no |
134+
| cloudtrail_org_id | AWS Organization ID for CloudTrail. | `string` | `""` | no |
135+
| cloudwatch_logs_prefix | S3 prefix for CloudWatch log exports. | `string` | `"cloudwatch"` | no |
136+
| config_accounts | List of accounts for Config logs. By default limits to the current account. | `list(string)` | `[]` | no |
137+
| config_logs_prefix | S3 prefix for AWS Config logs. | `string` | `"config"` | no |
138+
| control_object_ownership | Whether to manage S3 Bucket Ownership Controls on this bucket. | `bool` | `true` | no |
139+
| create_public_access_block | Whether to create a public_access_block restricting public access to the bucket. | `bool` | `true` | no |
140+
| default_allow | Whether all services included in this module should be allowed to write to the bucket by default. Alternatively select individual services. It's recommended to use the default bucket ACL of log-delivery-write. | `bool` | `true` | no |
141+
| elb_accounts | List of accounts for ELB logs. By default limits to the current account. | `list(string)` | `[]` | no |
142+
| elb_logs_prefix | S3 prefix for ELB logs. | `list(string)` | ```[ "elb" ]``` | no |
143+
| enable_mfa_delete | A bool that requires MFA to delete the log bucket. | `bool` | `false` | no |
144+
| enable_s3_log_bucket_lifecycle_rule | Whether the lifecycle rule for the log bucket is enabled. | `bool` | `true` | no |
145+
| force_destroy | A bool that indicates all objects (including any locked objects) should be deleted from the bucket so the bucket can be destroyed without error. | `bool` | `false` | no |
146+
| kms_master_key_id | The AWS KMS master key ID used for the SSE-KMS encryption. If blank, bucket encryption configuration defaults to AES256. | `string` | `""` | no |
147+
| logging_target_bucket | S3 Bucket to send S3 logs to. Disables logging if omitted. | `string` | `""` | no |
148+
| logging_target_prefix | Prefix for logs going into the log_s3_bucket. | `string` | `"s3/"` | no |
149+
| nlb_account | Account for NLB logs. By default limits to the current account. | `string` | `""` | no |
150+
| nlb_logs_prefixes | S3 key prefixes for NLB logs. | `list(string)` | ```[ "nlb" ]``` | no |
151+
| noncurrent_version_retention | Number of days to retain non-current versions of objects if versioning is enabled. | `string` | `30` | no |
152+
| object_ownership | Object ownership. Valid values: BucketOwnerEnforced, BucketOwnerPreferred or ObjectWriter. | `string` | `"BucketOwnerEnforced"` | no |
153+
| redshift_logs_prefix | S3 prefix for RedShift logs. | `string` | `"redshift"` | no |
154+
| s3_bucket_acl | Set bucket ACL per [AWS S3 Canned ACL](<https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl>) list. | `string` | `null` | no |
155+
| s3_log_bucket_retention | Number of days to keep AWS logs around. | `string` | `90` | no |
156+
| s3_logs_prefix | S3 prefix for S3 access logs. | `string` | `"s3"` | no |
159157
| tags | A mapping of tags to assign to the logs bucket. Please note that tags with a conflicting key will not override the original tag. | `map(string)` | `{}` | no |
160-
| versioning\_status | A string that indicates the versioning status for the log bucket. | `string` | `"Disabled"` | no |
158+
| versioning_status | A string that indicates the versioning status for the log bucket. | `string` | `"Disabled"` | no |
161159

162160
## Outputs
163161

164162
| Name | Description |
165163
|------|-------------|
166-
| aws\_logs\_bucket | ID of the S3 bucket containing AWS logs. |
167-
| bucket\_arn | ARN of the S3 logs bucket |
168-
| configs\_logs\_path | S3 path for Config logs. |
169-
| elb\_logs\_path | S3 path for ELB logs. |
170-
| redshift\_logs\_path | S3 path for RedShift logs. |
171-
| s3\_bucket\_policy | S3 bucket policy |
164+
| aws_logs_bucket | ID of the S3 bucket containing AWS logs. |
165+
| bucket_arn | ARN of the S3 logs bucket |
166+
| configs_logs_path | S3 path for Config logs. |
167+
| elb_logs_path | S3 path for ELB logs. |
168+
| redshift_logs_path | S3 path for RedShift logs. |
169+
| s3_bucket_policy | S3 bucket policy |
172170
<!-- END_TF_DOCS -->
173171

174172
## Upgrade Paths

examples/logging_target_bucket/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ module "aws_logs_logs" {
2424

2525
s3_bucket_name = local.log_bucket_name
2626

27-
default_allow = false
27+
default_allow = false
28+
allow_s3 = true
29+
s3_logs_prefix = [var.s3_logs_prefix]
30+
2831

2932
force_destroy = var.force_destroy
3033
}

main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ data "aws_iam_policy_document" "main" {
255255
variable = "s3:x-amz-acl"
256256
values = ["bucket-owner-full-control"]
257257
}
258-
resources = ["${local.bucket_arn}/${local.config_logs_path}/${statement.value}/Config/*"]
258+
resources = local.config_resources
259259
}
260260
}
261261
#
@@ -450,8 +450,10 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "aws_logs" {
450450

451451
rule {
452452
apply_server_side_encryption_by_default {
453-
sse_algorithm = "AES256"
453+
sse_algorithm = length(var.kms_master_key_id) > 0 ? "aws:kms" : "AES256"
454+
kms_master_key_id = length(var.kms_master_key_id) > 0 ? var.kms_master_key_id : null
454455
}
456+
bucket_key_enabled = var.bucket_key_enabled
455457
}
456458
}
457459

renovate.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
{
22
"extends": [
3-
"config:base"
3+
"config:recommended",
4+
"helpers:pinGitHubActionDigests"
45
],
56
"labels": [
67
"dependencies"
78
],
89
"packageRules": [
10+
{
11+
"automerge": true,
12+
"description": "Automerge all updates except major versions",
13+
"matchUpdateTypes": [
14+
"patch",
15+
"pin",
16+
"digest",
17+
"minor"
18+
]
19+
},
920
{
1021
"description": "Tag the waddlers Github Team for major updates",
1122
"matchUpdateTypes": [
@@ -19,11 +30,14 @@
1930
"automerge": true,
2031
"description": "Group minor and patch updates into a single PR",
2132
"groupName": "dependencies",
33+
"matchManagers": [
34+
"terraform",
35+
"pre-commit",
36+
"github-actions"
37+
],
2238
"matchUpdateTypes": [
2339
"minor",
24-
"patch",
25-
"pin",
26-
"digest"
40+
"patch"
2741
]
2842
}
2943
],

0 commit comments

Comments
 (0)