From da14f7d9c2edc47cec87345f5155d2149ef5da95 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:31:52 -0800 Subject: [PATCH 01/11] test --- common.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common.tf b/common.tf index 30276a5..2e484c3 100644 --- a/common.tf +++ b/common.tf @@ -51,12 +51,13 @@ data "aws_iam_policy_document" "waggle_dance_glue_policy" { data "aws_secretsmanager_secret" "datadog_key" { + count = length(data.aws_secretsmanager_secret.datadog_key) > 0 ? 1 : 0 name = var.datadog_key_secret_name } data "aws_secretsmanager_secret_version" "datadog_key" { count = length(data.aws_secretsmanager_secret.datadog_key) > 0 ? 1 : 0 - secret_id = data.aws_secretsmanager_secret.datadog_key.id + secret_id = data.aws_secretsmanager_secret.datadog_key[0].id } locals { From 4b143f29349914b1f2f0005208d367256d2b3ee8 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:44:47 -0800 Subject: [PATCH 02/11] test --- common.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.tf b/common.tf index 2e484c3..829107e 100644 --- a/common.tf +++ b/common.tf @@ -61,7 +61,7 @@ data "aws_secretsmanager_secret_version" "datadog_key" { } locals { - datadog_keys = jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) + datadog_keys = length(data.aws_secretsmanager_secret.datadog_key) > 0 ? {} : jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) } provider "datadog" { From df7344b373009f80e72d803e882568cee9eab217 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:47:44 -0800 Subject: [PATCH 03/11] test --- common.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common.tf b/common.tf index 829107e..3087ac8 100644 --- a/common.tf +++ b/common.tf @@ -51,17 +51,17 @@ data "aws_iam_policy_document" "waggle_dance_glue_policy" { data "aws_secretsmanager_secret" "datadog_key" { - count = length(data.aws_secretsmanager_secret.datadog_key) > 0 ? 1 : 0 + count = length(var.datadog_key_secret_name) > 0 ? 1 : 0 name = var.datadog_key_secret_name } data "aws_secretsmanager_secret_version" "datadog_key" { - count = length(data.aws_secretsmanager_secret.datadog_key) > 0 ? 1 : 0 + count = length(var.datadog_key_secret_name) > 0 ? 1 : 0 secret_id = data.aws_secretsmanager_secret.datadog_key[0].id } locals { - datadog_keys = length(data.aws_secretsmanager_secret.datadog_key) > 0 ? {} : jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) + datadog_keys = length(var.var.datadog_key_secret_name) > 0 ? {} : jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) } provider "datadog" { From 2b3255477fc7285ac5bfe8dd8dd4bd90d96b01a9 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:49:25 -0800 Subject: [PATCH 04/11] update var.datadog_key_secret_name default value --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index efde532..24a51ab 100644 --- a/variables.tf +++ b/variables.tf @@ -381,7 +381,7 @@ variable "tcp_keepalive_probes" { variable "datadog_key_secret_name" { description = "Name of the secret containing the DataDog API key. This needs to be created manually in AWS secrets manager. This is only applicable to ECS deployments." type = string - default = null + default = "" } variable "datadog_agent_version" { From 631e8aaf4b559c9625d62649203a3f78c06281f4 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:53:18 -0800 Subject: [PATCH 05/11] change conditional expression --- templates.tf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates.tf b/templates.tf index 46bee65..4b00852 100644 --- a/templates.tf +++ b/templates.tf @@ -197,11 +197,11 @@ data "template_file" "datadog-agent" { template = file("${path.module}/templates/datadog-agent.json") vars = { - region = var.aws_region - loggroup = var.wd_instance_type == "ecs" ? join("", aws_cloudwatch_log_group.waggledance_ecs.*.name) : "" - datadog_secret_key = jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string).api_key - wd_instance_type = var.wd_instance_type - metrics_port = var.metrics_port + region = var.aws_region + loggroup = var.wd_instance_type == "ecs" ? join("", aws_cloudwatch_log_group.waggledance_ecs.*.name) : "" + datadog_secret_key = local.datadog_keys.api_key != null ? local.datadog_keys.api_key : "" + wd_instance_type = var.wd_instance_type + metrics_port = var.metrics_port datadog_agent_version = var.datadog_agent_version } } From 982dbc2808bf542444315c32c00f3659197b4d83 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:55:13 -0800 Subject: [PATCH 06/11] change conditional expression --- common.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.tf b/common.tf index 3087ac8..92cbec9 100644 --- a/common.tf +++ b/common.tf @@ -61,7 +61,7 @@ data "aws_secretsmanager_secret_version" "datadog_key" { } locals { - datadog_keys = length(var.var.datadog_key_secret_name) > 0 ? {} : jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) + datadog_keys = length(var.var.datadog_key_secret_name) > 0 ? [] : jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) } provider "datadog" { From 01284f44319aec8b6eb066fc1dec5a63eab3447b Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:59:38 -0800 Subject: [PATCH 07/11] fix typo --- common.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.tf b/common.tf index 92cbec9..6543688 100644 --- a/common.tf +++ b/common.tf @@ -61,7 +61,7 @@ data "aws_secretsmanager_secret_version" "datadog_key" { } locals { - datadog_keys = length(var.var.datadog_key_secret_name) > 0 ? [] : jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) + datadog_keys = length(var.datadog_key_secret_name) > 0 ? [] : jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) } provider "datadog" { From 03a20c6be1df6db8e3b18dde14b9e97456628c04 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:08:27 -0800 Subject: [PATCH 08/11] update secret --- common.tf | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common.tf b/common.tf index 6543688..74c7393 100644 --- a/common.tf +++ b/common.tf @@ -60,11 +60,12 @@ data "aws_secretsmanager_secret_version" "datadog_key" { secret_id = data.aws_secretsmanager_secret.datadog_key[0].id } -locals { - datadog_keys = length(var.datadog_key_secret_name) > 0 ? [] : jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string) +data "external" "datadog_key" { + count = length(var.datadog_key_secret_name) > 0 ? 1 : 0 + program = ["echo", "${data.aws_secretsmanager_secret_version.datadog_key[0].secret_string}"] } provider "datadog" { - api_key = local.datadog_keys.api_key != null ? local.datadog_keys.api_key : "" - app_key = local.datadog_keys.app_key != null ? local.datadog_keys.app_key : "" + api_key = chomp(data.external.datadog_key.result["api_key"]) + app_key = chomp(data.external.datadog_key.result["app_key"]) } From 62687c44d6408f470b37df3a1df03387f1404933 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:09:06 -0800 Subject: [PATCH 09/11] Update common.tf --- common.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common.tf b/common.tf index 74c7393..dc38331 100644 --- a/common.tf +++ b/common.tf @@ -66,6 +66,6 @@ data "external" "datadog_key" { } provider "datadog" { - api_key = chomp(data.external.datadog_key.result["api_key"]) - app_key = chomp(data.external.datadog_key.result["app_key"]) + api_key = chomp(data.external.datadog_key[0].result["api_key"]) + app_key = chomp(data.external.datadog_key[0].result["app_key"]) } From 0625d11c11f717b1472c8bb9469bac52293a1fbb Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:09:37 -0800 Subject: [PATCH 10/11] Update templates.tf --- templates.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates.tf b/templates.tf index 4b00852..a3bbf9a 100644 --- a/templates.tf +++ b/templates.tf @@ -199,7 +199,7 @@ data "template_file" "datadog-agent" { vars = { region = var.aws_region loggroup = var.wd_instance_type == "ecs" ? join("", aws_cloudwatch_log_group.waggledance_ecs.*.name) : "" - datadog_secret_key = local.datadog_keys.api_key != null ? local.datadog_keys.api_key : "" + datadog_secret_key = chomp(data.external.datadog_key[0].result["api_key"]) wd_instance_type = var.wd_instance_type metrics_port = var.metrics_port datadog_agent_version = var.datadog_agent_version From 18f653c763e7681ab9ec89ee6809b964bb43cca5 Mon Sep 17 00:00:00 2001 From: githubjianli <51385385+githubjianli@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:14:11 -0800 Subject: [PATCH 11/11] Update templates.tf --- templates.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates.tf b/templates.tf index a3bbf9a..813d755 100644 --- a/templates.tf +++ b/templates.tf @@ -199,7 +199,7 @@ data "template_file" "datadog-agent" { vars = { region = var.aws_region loggroup = var.wd_instance_type == "ecs" ? join("", aws_cloudwatch_log_group.waggledance_ecs.*.name) : "" - datadog_secret_key = chomp(data.external.datadog_key[0].result["api_key"]) + datadog_secret_key = length(var.datadog_key_secret_name) > 0 ? chomp(data.external.datadog_key[0].result["api_key"]) : "" wd_instance_type = var.wd_instance_type metrics_port = var.metrics_port datadog_agent_version = var.datadog_agent_version