Skip to content

Commit 7abff70

Browse files
dmattiaaknysh
andcommitted
Allow disabling the logging bucket (#71)
Fixes #24 Co-authored-by: Andriy Knysh <[email protected]>
1 parent 9d52048 commit 7abff70

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ Available targets:
182182
| log_include_cookies | Include cookies in access logs | bool | `false` | no |
183183
| log_prefix | Path of logs in S3 bucket | string | `` | no |
184184
| log_standard_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier | number | `30` | no |
185+
| logging_enabled | When true, access logs will be sent to a newly created s3 bucket | bool | `true` | no |
185186
| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | number | `31536000` | no |
186187
| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | number | `0` | no |
187188
| minimum_protocol_version | Cloudfront TLS minimum protocol version | string | `TLSv1` | no |
@@ -359,8 +360,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
359360

360361
### Contributors
361362

362-
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Jamie Nelson][Jamie-BitFlight_avatar]][Jamie-BitFlight_homepage]<br/>[Jamie Nelson][Jamie-BitFlight_homepage] | [![Clive Zagno][cliveza_avatar]][cliveza_homepage]<br/>[Clive Zagno][cliveza_homepage] |
363-
|---|---|---|---|
363+
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Jamie Nelson][Jamie-BitFlight_avatar]][Jamie-BitFlight_homepage]<br/>[Jamie Nelson][Jamie-BitFlight_homepage] | [![Clive Zagno][cliveza_avatar]][cliveza_homepage]<br/>[Clive Zagno][cliveza_homepage] | [![David Mattia][dmattia_avatar]][dmattia_homepage]<br/>[David Mattia][dmattia_homepage] |
364+
|---|---|---|---|---|
364365

365366
[osterman_homepage]: https://github.com/osterman
366367
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
@@ -370,6 +371,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
370371
[Jamie-BitFlight_avatar]: https://img.cloudposse.com/150x150/https://github.com/Jamie-BitFlight.png
371372
[cliveza_homepage]: https://github.com/cliveza
372373
[cliveza_avatar]: https://img.cloudposse.com/150x150/https://github.com/cliveza.png
374+
[dmattia_homepage]: https://github.com/dmattia
375+
[dmattia_avatar]: https://img.cloudposse.com/150x150/https://github.com/dmattia.png
373376

374377
[![README Footer][readme_footer_img]][readme_footer_link]
375378
[![Beacon][beacon]][website]

README.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,5 @@ contributors:
111111
github: "Jamie-BitFlight"
112112
- name: "Clive Zagno"
113113
github: "cliveza"
114+
- name: "David Mattia"
115+
github: "dmattia"

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
| log_include_cookies | Include cookies in access logs | bool | `false` | no |
3939
| log_prefix | Path of logs in S3 bucket | string | `` | no |
4040
| log_standard_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier | number | `30` | no |
41+
| logging_enabled | When true, access logs will be sent to a newly created s3 bucket | bool | `true` | no |
4142
| max_ttl | Maximum amount of time (in seconds) that an object is in a CloudFront cache | number | `31536000` | no |
4243
| min_ttl | Minimum amount of time that you want objects to stay in CloudFront caches | number | `0` | no |
4344
| minimum_protocol_version | Cloudfront TLS minimum protocol version | string | `TLSv1` | no |

main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ resource "aws_s3_bucket" "origin" {
119119

120120
module "logs" {
121121
source = "git::https://github.com/cloudposse/terraform-aws-s3-log-storage.git?ref=tags/0.7.0"
122+
enabled = var.logging_enabled
122123
namespace = var.namespace
123124
stage = var.stage
124125
name = var.name
@@ -168,10 +169,13 @@ resource "aws_cloudfront_distribution" "default" {
168169
price_class = var.price_class
169170
depends_on = [aws_s3_bucket.origin]
170171

171-
logging_config {
172-
include_cookies = var.log_include_cookies
173-
bucket = module.logs.bucket_domain_name
174-
prefix = var.log_prefix
172+
dynamic "logging_config" {
173+
for_each = var.logging_enabled ? ["true"] : []
174+
content {
175+
include_cookies = var.log_include_cookies
176+
bucket = module.logs.bucket_domain_name
177+
prefix = var.log_prefix
178+
}
175179
}
176180

177181
aliases = var.acm_certificate_arn != "" ? var.aliases : []

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ variable "comment" {
124124
description = "Comment for the origin access identity"
125125
}
126126

127+
variable "logging_enabled" {
128+
type = bool
129+
default = true
130+
description = "When true, access logs will be sent to a newly created s3 bucket"
131+
}
132+
127133
variable "log_include_cookies" {
128134
type = bool
129135
default = false

0 commit comments

Comments
 (0)