From 13553901fe0cba4cd9ab65a3d5281076e6d30c4f Mon Sep 17 00:00:00 2001 From: Ryan Tan Date: Thu, 20 Jul 2023 08:16:00 +0800 Subject: [PATCH 1/5] if subsystem_name is empty, do not add as param --- modules/firehose/main.tf | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/firehose/main.tf b/modules/firehose/main.tf index 981fd599..cf5ef6ea 100644 --- a/modules/firehose/main.tf +++ b/modules/firehose/main.tf @@ -182,9 +182,12 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_kinesis_s value = local.application_name } - common_attributes { - name = "subsystemName" - value = var.subsystem_name + dynamic common_attributes { + for_each = var.subsystem_name == "" ? [] : [1] + content { + name = "subsystemName" + value = var.subsystem_name + } } common_attributes { @@ -239,9 +242,12 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_direct_pu value = local.application_name } - common_attributes { - name = "subsystemName" - value = var.subsystem_name + dynamic common_attributes { + for_each = var.subsystem_name == "" ? [] : [1] + content { + name = "subsystemName" + value = var.subsystem_name + } } common_attributes { From e6eb7ef8d8e5ef05bda44be3a0ea6afd8e54df8c Mon Sep 17 00:00:00 2001 From: Ryan Tan Date: Thu, 20 Jul 2023 15:02:46 +0800 Subject: [PATCH 2/5] changes to applicationName and integrationType also, non-mandatory param --- modules/firehose/README.md | 2 +- modules/firehose/main.tf | 63 ++++++++++++++++++++++------------- modules/firehose/variables.tf | 2 +- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/modules/firehose/README.md b/modules/firehose/README.md index f224d7c5..7322885c 100644 --- a/modules/firehose/README.md +++ b/modules/firehose/README.md @@ -185,7 +185,7 @@ then the CloudWatch metric stream must be configured with the same format, confi | [logs_enable](#input\_logs_enable) | Enble sending logs to Coralogix | `bool` | `false` | no | | [source_type_logs](#input\_source_type_logs) | The source_type of kinesis firehose: KinesisStreamAsSource or DirectPut | `string` | `DirectPut` | no | | [kinesis_stream_arn](#input\_kinesis_stream_arn) | The kinesis stream name for the logs - used in kinesis stream as a source | `string` | `""` | no | -| [kinesis_stream_arn](#input\_integration_type_logs) | The integration type of the firehose delivery stream: 'CloudWatch_JSON', 'WAF', 'CloudWatch_CloudTrail', 'EksFargate', 'Default', 'RawText' | `string` | `Default` | no | +| [integration_type_logs](#input\_integration_type_logs) | The integration type of the firehose delivery stream: 'CloudWatch_JSON', 'WAF', 'CloudWatch_CloudTrail', 'EksFargate', 'Default', 'RawText' | `string` | `Default` | no | | [dynamic_metadata_logs](#input\_dynamic_metadata_logs) | Dynamic values search for specific fields in the logs to populate the fields | `bool` | `false` | no | diff --git a/modules/firehose/main.tf b/modules/firehose/main.tf index cf5ef6ea..9a3be07f 100644 --- a/modules/firehose/main.tf +++ b/modules/firehose/main.tf @@ -31,7 +31,6 @@ locals { managed-by = "coralogix-terraform" custom_endpoint = var.coralogix_firehose_custom_endpoint != null ? var.coralogix_firehose_custom_endpoint : "" }) - application_name = var.application_name == null ? "coralogix-${var.firehose_stream}" : var.application_name } data "aws_caller_identity" "current_identity" {} @@ -172,21 +171,27 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_kinesis_s request_configuration { content_encoding = "GZIP" - common_attributes { - name = "integrationType" - value = var.integration_type_logs + dynamic "common_attributes" { + for_each = var.integration_type_logs == "" ? [] : [1] + content { + name = "integrationType" + value = var.integration_type_logs + } } - common_attributes { - name = "applicationName" - value = local.application_name + dynamic "common_attributes" { + for_each = var.application_name == "" ? [] : [1] + content { + name = "applicationName" + value = var.application_name + } } - dynamic common_attributes { + dynamic "common_attributes" { for_each = var.subsystem_name == "" ? [] : [1] content { name = "subsystemName" - value = var.subsystem_name + value = var.subsystem_name } } @@ -232,21 +237,27 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_direct_pu request_configuration { content_encoding = "GZIP" - common_attributes { - name = "integrationType" - value = var.integration_type_logs + dynamic "common_attributes" { + for_each = var.integration_type_logs == "" ? [] : [1] + content { + name = "integrationType" + value = var.integration_type_logs + } } - common_attributes { - name = "applicationName" - value = local.application_name + dynamic "common_attributes" { + for_each = var.application_name == "" ? [] : [1] + content { + name = "applicationName" + value = var.application_name + } } - dynamic common_attributes { + dynamic "common_attributes" { for_each = var.subsystem_name == "" ? [] : [1] content { name = "subsystemName" - value = var.subsystem_name + value = var.subsystem_name } } @@ -471,14 +482,20 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_metrics" { request_configuration { content_encoding = "GZIP" - common_attributes { - name = "integrationType" - value = var.integration_type_metrics + dynamic "common_attributes" { + for_each = var.integration_type_logs == "" ? [] : [1] + content { + name = "integrationType" + value = var.integration_type_logs + } } - common_attributes { - name = "applicationName" - value = local.application_name + dynamic "common_attributes" { + for_each = var.application_name == "" ? [] : [1] + content { + name = "applicationName" + value = var.application_name + } } } diff --git a/modules/firehose/variables.tf b/modules/firehose/variables.tf index c0252375..3ef71578 100644 --- a/modules/firehose/variables.tf +++ b/modules/firehose/variables.tf @@ -110,7 +110,7 @@ variable "kinesis_stream_arn" { variable "integration_type_logs" { description = "The integration type of the firehose delivery stream: 'CloudWatch_JSON', 'WAF', 'CloudWatch_CloudTrail', 'EksFargate', 'Default', 'RawText'" type = string - default = "Default" + default = "" } variable "dynamic_metadata_logs" { From 511ad55f59894af3de4f57833a982840a76b5aff Mon Sep 17 00:00:00 2001 From: Ryan Tan Date: Thu, 20 Jul 2023 15:14:35 +0800 Subject: [PATCH 3/5] integration_type_metrics remove default --- modules/firehose/variables.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/firehose/variables.tf b/modules/firehose/variables.tf index 3ef71578..d5cf9c5b 100644 --- a/modules/firehose/variables.tf +++ b/modules/firehose/variables.tf @@ -49,7 +49,7 @@ variable "output_format" { variable "integration_type_metrics" { description = "The integration type of the firehose delivery stream: 'CloudWatch_Metrics_JSON' or 'CloudWatch_Metrics_OpenTelemetry070'" type = string - default = "CloudWatch_Metrics_OpenTelemetry070" + default = "" } variable "application_name" { @@ -94,7 +94,6 @@ variable "metric_enable" { default = true } -#for logs: variable "source_type_logs" { description = "The source_type of kinesis firehose: KinesisStreamAsSource or DirectPut" type = string From e46d968b7cb4082944b31ee4b2961decd4ae983a Mon Sep 17 00:00:00 2001 From: Ryan Tan Date: Fri, 21 Jul 2023 00:03:42 +0800 Subject: [PATCH 4/5] default to null which will not include --- modules/firehose/main.tf | 32 +++++++++++++++++++------------- modules/firehose/variables.tf | 4 ++-- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/modules/firehose/main.tf b/modules/firehose/main.tf index 3a19c37e..4f14ed0b 100644 --- a/modules/firehose/main.tf +++ b/modules/firehose/main.tf @@ -172,7 +172,7 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_kinesis_s content_encoding = "GZIP" dynamic "common_attributes" { - for_each = var.integration_type_logs == "" ? [] : [1] + for_each = var.integration_type_logs == null ? [] : [1] content { name = "integrationType" value = var.integration_type_logs @@ -180,7 +180,7 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_kinesis_s } dynamic "common_attributes" { - for_each = var.application_name == "" ? [] : [1] + for_each = var.application_name == null ? [] : [1] content { name = "applicationName" value = var.application_name @@ -188,7 +188,7 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_kinesis_s } dynamic "common_attributes" { - for_each = var.subsystem_name == "" ? [] : [1] + for_each = var.subsystem_name == null ? [] : [1] content { name = "subsystemName" value = var.subsystem_name @@ -237,21 +237,27 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_direct_pu content_encoding = "GZIP" dynamic "common_attributes" { - for_each = var.integration_type_logs == "" ? [] : [1] + for_each = var.integration_type_logs == null ? [] : [1] content { name = "integrationType" value = var.integration_type_logs } } - common_attributes { - name = "applicationName" - value = local.application_name + dynamic "common_attributes" { + for_each = var.application_name == null ? [] : [1] + content { + name = "applicationName" + value = var.application_name + } } - common_attributes { - name = "subsystemName" - value = var.subsystem_name + dynamic "common_attributes" { + for_each = var.subsystem_name == null ? [] : [1] + content { + name = "subsystemName" + value = var.subsystem_name + } } common_attributes { @@ -476,15 +482,15 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_metrics" { content_encoding = "GZIP" dynamic "common_attributes" { - for_each = var.integration_type_logs == "" ? [] : [1] + for_each = var.integration_type_metrics == null ? [] : [1] content { name = "integrationType" - value = var.integration_type_logs + value = var.integration_type_metrics } } dynamic "common_attributes" { - for_each = var.application_name == "" ? [] : [1] + for_each = var.application_name == null ? [] : [1] content { name = "applicationName" value = var.application_name diff --git a/modules/firehose/variables.tf b/modules/firehose/variables.tf index d5cf9c5b..6c90e41a 100644 --- a/modules/firehose/variables.tf +++ b/modules/firehose/variables.tf @@ -61,7 +61,7 @@ variable "application_name" { variable "subsystem_name" { description = "The subsystem name of your application in Coralogix" type = string - default = "" + default = null } variable "user_supplied_tags" { @@ -109,7 +109,7 @@ variable "kinesis_stream_arn" { variable "integration_type_logs" { description = "The integration type of the firehose delivery stream: 'CloudWatch_JSON', 'WAF', 'CloudWatch_CloudTrail', 'EksFargate', 'Default', 'RawText'" type = string - default = "" + default = null } variable "dynamic_metadata_logs" { From 31cc6ebfc852c7073e86b7e0be813d8b94669147 Mon Sep 17 00:00:00 2001 From: Ryan Tan Date: Sat, 22 Jul 2023 01:41:16 +0800 Subject: [PATCH 5/5] dynamic_metadata_logs also --- modules/firehose/main.tf | 18 ++++++++++++------ modules/firehose/variables.tf | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/firehose/main.tf b/modules/firehose/main.tf index 4f14ed0b..feb43d4c 100644 --- a/modules/firehose/main.tf +++ b/modules/firehose/main.tf @@ -195,9 +195,12 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_kinesis_s } } - common_attributes { - name = "dynamicMetadata" - value = var.dynamic_metadata_logs + dynamic "common_attributes" { + for_each = var.dynamic_metadata_logs == null ? [] : [1] + content { + name = "dynamicMetadata" + value = var.dynamic_metadata_logs + } } } } @@ -260,9 +263,12 @@ resource "aws_kinesis_firehose_delivery_stream" "coralogix_stream_logs_direct_pu } } - common_attributes { - name = "dynamicMetadata" - value = var.dynamic_metadata_logs + dynamic "common_attributes" { + for_each = var.dynamic_metadata_logs == null ? [] : [1] + content { + name = "dynamicMetadata" + value = var.dynamic_metadata_logs + } } } } diff --git a/modules/firehose/variables.tf b/modules/firehose/variables.tf index 6c90e41a..b2a6450b 100644 --- a/modules/firehose/variables.tf +++ b/modules/firehose/variables.tf @@ -115,5 +115,5 @@ variable "integration_type_logs" { variable "dynamic_metadata_logs" { description = "Dynamic values search for specific fields in the logs to populate the fields" type = bool - default = false + default = null }