Skip to content

Commit

Permalink
Setup logging via aws_redshift_logging resource
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian-lesko committed Oct 23, 2024
1 parent d24c370 commit c31ae29
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
21 changes: 15 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ resource "aws_redshift_cluster" "default" {
iam_roles = var.iam_roles
allow_version_upgrade = var.allow_version_upgrade

logging {
enable = var.logging_enabled
bucket_name = var.logging_bucket_name
s3_key_prefix = var.logging_s3_key_prefix
}

depends_on = [
aws_redshift_subnet_group.default,
aws_redshift_parameter_group.default
]

tags = module.this.tags

lifecycle {
ignore_changes = [logging]
}
}

resource "aws_redshift_subnet_group" "default" {
Expand Down Expand Up @@ -76,3 +74,14 @@ resource "aws_redshift_parameter_group" "default" {

tags = module.this.tags
}

resource "aws_redshift_logging" "default" {
count = local.enabled && var.logging_enabled ? 1 : 0

cluster_identifier = aws_redshift_cluster.default[0].id
log_destination_type = var.logging_log_destination_type
log_exports = var.logging_log_exports

bucket_name = var.logging_bucket_name
s3_key_prefix = var.logging_s3_key_prefix
}
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ variable "logging_enabled" {
description = "If true, enables logging information such as queries and connection attempts, for the specified Amazon Redshift cluster"
}

variable "logging_log_destination_type" {
type = string
default = null
description = "Log destination type for the Redshift cluster ('s3' or 'cloudwatch')."
}

variable "logging_log_exports" {
type = list(string)
default = []
description = "Log destination types for the cluster (one or more of 'connectionlog', 'useractivitylog', 'userlog')."
}

variable "logging_bucket_name" {
type = string
default = null
Expand Down

0 comments on commit c31ae29

Please sign in to comment.