Reputation: 1
I'm trying to add a default tag (team = "terraform") to Datadog monitors using Terraform and any new created monitor will have that tag added automatically. I used the default_tags at the datadog provider level works fine without modules, But not working when using modules. I not sure where to define those tags.
Here is part of the main.tf file.
/terraform/main.tf
provider "datadog" {
api_key = var.datadog_api_key
app_key = var.datadog_app_key
default_tags {
tags = {
team = "terraform"
}
}
}
module "AMQ"{
source = "./AMQ_templates"
aws_access_key = var.aws_access_key
aws_secret_key = var.aws_secret_key
datadog_api_key = var.datadog_api_key
datadog_app_key = var.datadog_app_key
}
and this is one of the monitors that I'm using amq_template_cpu.tf
/terraform/AMQ_templates/amq_template_cpu.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.40"
}
datadog = {
source = "DataDog/datadog"
}
}
}
provider "aws" {
region = "us-east-1"
access_key = var.aws_access_key
secret_key = var.aws_secret_key
}
# Configure the Datadog provider
provider "datadog" {
api_key = var.datadog_api_key
app_key = var.datadog_app_key
}
resource "datadog_monitor" "TEMPLATE_AMQ_Broker_CPU_Terraform"{
evaluation_delay = 900
new_group_delay = 60
require_full_window = false
monitor_thresholds {
critical = 90
warning = 60
}
name = "[TEMPLATE] - AMQ Broker - Warning - Threshold - CPU Utilization on {{broker.name}} is Out of Trend - Terraform "
type = "query alert"
query = <<EOT
avg(last_15m):default_zero(avg:aws.amazonmq.cpu_utilization{env:prod} by {broker}) > 90
EOT
message = <<EOT
**Alert Description:** {{broker.name}} is out of trend and may need remediation
**User Impact:** Describe what users are experiencing if this alert fires.
And I'm using a different file for variables variables.tf
variable "datadog_api_key" {
type = string
}
variable "datadog_app_key" {
type = string
}
variable "aws_access_key" {
description = "AWS access key"
type = string
}
variable "aws_secret_key" {
description = "AWS secret key"
type = string
}
Upvotes: -1
Views: 53