Skip to content

Commit 0ac9ed3

Browse files
committed
refactor(logging): use distribution tags and support all destination types
- Remove dedicated tags from logging variables, use var.tags instead - Add delivery_destination_type parameter for X-Ray trace delivery support - Make destination_arn optional (not required for X-Ray) - Make delivery_destination_configuration a dynamic block
1 parent 75518ec commit 0ac9ed3

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ No modules.
213213
| <a name="input_restrictions"></a> [restrictions](#input\_restrictions) | The restrictions configuration for this distribution | <pre>object({<br/> geo_restriction = object({<br/> locations = optional(list(string))<br/> restriction_type = optional(string, "none")<br/> })<br/> })</pre> | <pre>{<br/> "geo_restriction": {<br/> "restriction_type": "none"<br/> }<br/>}</pre> | no |
214214
| <a name="input_retain_on_delete"></a> [retain\_on\_delete](#input\_retain\_on\_delete) | Disables the distribution instead of deleting it when destroying the resource through Terraform. If this is set, the distribution needs to be deleted manually afterwards | `bool` | `null` | no |
215215
| <a name="input_staging"></a> [staging](#input\_staging) | Whether the distribution is a staging distribution | `bool` | `null` | no |
216-
| <a name="input_std_logging_delivery"></a> [std\_logging\_delivery](#input\_std\_logging\_delivery) | Configuration for the standard logging delivery | <pre>object({<br/> field_delimiter = optional(string)<br/> record_fields = optional(list(string))<br/> s3_delivery_configuration = optional(object({<br/> enable_hive_compatible_path = optional(bool)<br/> suffix_path = optional(string)<br/> }))<br/> tags = optional(map(string), {})<br/> })</pre> | `null` | no |
217-
| <a name="input_std_logging_destination"></a> [std\_logging\_destination](#input\_std\_logging\_destination) | Configuration for creating a new standard logging destination. Ignored if std\_logging\_destination\_arn is set | <pre>object({<br/> name = string<br/> output_format = optional(string, "json")<br/> destination_arn = string<br/> tags = optional(map(string), {})<br/> })</pre> | `null` | no |
216+
| <a name="input_std_logging_delivery"></a> [std\_logging\_delivery](#input\_std\_logging\_delivery) | Configuration for the standard logging delivery | <pre>object({<br/> field_delimiter = optional(string)<br/> record_fields = optional(list(string))<br/> s3_delivery_configuration = optional(object({<br/> enable_hive_compatible_path = optional(bool)<br/> suffix_path = optional(string)<br/> }))<br/> })</pre> | `null` | no |
217+
| <a name="input_std_logging_destination"></a> [std\_logging\_destination](#input\_std\_logging\_destination) | Configuration for creating a new standard logging destination. Ignored if std\_logging\_destination\_arn is set | <pre>object({<br/> name = string<br/> output_format = optional(string, "json") # json, plain, w3c, raw, parquet<br/> destination_arn = optional(string) # Required for S3, CloudWatch Logs, Firehose. Not required for X-Ray<br/> delivery_destination_type = optional(string) # S3, CWL, FH, XRAY. Auto-detected from destination_arn if not set<br/> })</pre> | `null` | no |
218218
| <a name="input_std_logging_destination_arn"></a> [std\_logging\_destination\_arn](#input\_std\_logging\_destination\_arn) | ARN of an existing CloudWatch Log Delivery Destination to use. If set, std\_logging\_destination is ignored | `string` | `null` | no |
219219
| <a name="input_std_logging_region"></a> [std\_logging\_region](#input\_std\_logging\_region) | Region for standard logging resources. Required for CloudFront (must be us-east-1 for the source) | `string` | `"us-east-1"` | no |
220220
| <a name="input_std_logging_source_name"></a> [std\_logging\_source\_name](#input\_std\_logging\_source\_name) | Name for the CloudWatch Log Delivery Source. Defaults to 'cloudfront-<distribution\_id>' | `string` | `null` | no |

main.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,19 @@ resource "aws_cloudwatch_log_delivery_destination" "this" {
553553

554554
region = var.std_logging_region
555555

556-
name = var.std_logging_destination.name
557-
output_format = var.std_logging_destination.output_format
556+
name = var.std_logging_destination.name
557+
output_format = var.std_logging_destination.output_format
558+
delivery_destination_type = var.std_logging_destination.delivery_destination_type
558559

559-
delivery_destination_configuration {
560-
destination_resource_arn = var.std_logging_destination.destination_arn
560+
dynamic "delivery_destination_configuration" {
561+
for_each = var.std_logging_destination.destination_arn != null ? [1] : []
562+
563+
content {
564+
destination_resource_arn = var.std_logging_destination.destination_arn
565+
}
561566
}
562567

563-
tags = var.std_logging_destination.tags
568+
tags = var.tags
564569
}
565570

566571
locals {
@@ -588,7 +593,7 @@ resource "aws_cloudwatch_log_delivery" "this" {
588593
}
589594
}
590595

591-
tags = try(var.std_logging_delivery.tags, {})
596+
tags = var.tags
592597
}
593598

594599
################################################################################

variables.tf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ variable "std_logging_destination_arn" {
485485
variable "std_logging_destination" {
486486
description = "Configuration for creating a new standard logging destination. Ignored if std_logging_destination_arn is set"
487487
type = object({
488-
name = string
489-
output_format = optional(string, "json")
490-
destination_arn = string
491-
tags = optional(map(string), {})
488+
name = string
489+
output_format = optional(string, "json") # json, plain, w3c, raw, parquet
490+
destination_arn = optional(string) # Required for S3, CloudWatch Logs, Firehose. Not required for X-Ray
491+
delivery_destination_type = optional(string) # S3, CWL, FH, XRAY. Auto-detected from destination_arn if not set
492492
})
493493
default = null
494494
}
@@ -502,7 +502,6 @@ variable "std_logging_delivery" {
502502
enable_hive_compatible_path = optional(bool)
503503
suffix_path = optional(string)
504504
}))
505-
tags = optional(map(string), {})
506505
})
507506
default = null
508507
}

0 commit comments

Comments
 (0)