commit 9e755e45cace332a1741caa07d4557d388b2db86 Author: Patrick de Ruiter Date: Tue Oct 5 10:26:16 2021 +0200 Made a lot of modifications to standardize it for general usage diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1565be3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.tfstate +*.tfstate.backup +.terraform +provider.tf +*.tfvars +**/*.tfvars +provider.tf +.github +.circleci diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..282b7d4 --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,23 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/datadog/datadog" { + version = "3.2.0" + constraints = "3.2.0" + hashes = [ + "h1:nfbkvIrUHhsI0cx7IfYDdwdn+C7nBaDvqp3lsZ2BcQw=", + "zh:0973526974954263941cc4bc4a4bbd5a56726c09ebd118a513b0106d2164863d", + "zh:0e89a0254f65951da832f73822592c46758e168a1ea3f7fa7eb6c79fe1e13a5d", + "zh:35145207a6b585e51775079eb6c114d7d555c4f8a928361915374cb28b2cbe46", + "zh:3fdf4e1d184fbad0aed31e851cd8465d9be9e7481fcfcd1b5c0da7a1eb582048", + "zh:42dfbf4ecd8779346fa4764ce9db99b993fe3c8aefb6eea32d293f9a0bc5cab0", + "zh:4e172436bdcbfb2e41fa43a58bc89a1d1e47178e7011d99ff87885c65ef3966c", + "zh:72d77a750399ec7ff51c38894d54e54c178f16aab726b36caf0094501124f918", + "zh:72e112c8d008418f40677533e855a8b79061892fb42b8296ea69e8246d6205f9", + "zh:753d154fb6fb32f064469d3a2e2c657b7d8d19c674189480dae2d2f3b93d524b", + "zh:b8dfdcc4402856c043a08e4befe39b042203d616ffb370b54c64a7b3def6ca55", + "zh:be523a10cb95220cb52375ac71e03d8f0f48b0d8f3534075aa22d37b5d335d86", + "zh:eb9f11a30d9303b422eea27b5d11a716a290c81b8c09e5457292fb378386f66c", + "zh:fce91b84c90ce97b7acc6e4ec2cb6f9f4518ae070e00d7ca8973edd585d0ea14", + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..d9fa811 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Terraform Datadog Application Dashboard + +This Terraform module configures a dashboard for your Kubernetes application. + +How-to set it up to work with your application is described below + +# Setup + +First you need to copy the contents of the example directory to a directory + +module "your_application_name" + source = git:// diff --git a/data.tf b/data.tf new file mode 100644 index 0000000..e69de29 diff --git a/example/main.tf b/example/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..2b1baa6 --- /dev/null +++ b/main.tf @@ -0,0 +1,104 @@ +resource "datadog_dashboard" "beacon" { + title = var.app_name + description = "A Datadog Dashboard for the ${kubernetes_deployment.beacon.metadata[0].name} deployment" + layout_type = "ordered" + is_read_only = true + + + widget { + hostmap_definition { + no_group_hosts = true + no_metric_hosts = true + node_type = "container" + title = "Kubernetes Pods" + + request { + fill { + q = "avg:process.stat.container.cpu.total_pct{image_name:${var.image_name}} by {host}" + } + } + + style { + palette = "hostmap_blues" + palette_flip = false + } + } + } + + widget { + timeseries_definition { + show_legend = false + title = "CPU Utilization" + + request { + display_type = "line" + q = "top(avg:docker.cpu.usage{image_name:${var.image_name}} by {docker_image,container_id}, 10, 'mean', 'desc')" + + style { + line_type = "solid" + line_width = "normal" + palette = "dog_classic" + } + } + + yaxis { + include_zero = true + max = "auto" + min = "auto" + scale = "linear" + } + } + } + + widget { + alert_graph_definition { + alert_id = datadog_monitor.beacon.id + title = "Kubernetes Node CPU" + viz_type = "timeseries" + } + } + + widget { + hostmap_definition { + no_group_hosts = true + no_metric_hosts = true + node_type = "host" + title = "Kubernetes Nodes" + + request { + fill { + q = "avg:system.cpu.user{*} by {host}" + } + } + + style { + palette = "hostmap_blues" + palette_flip = false + } + } + } + + widget { + timeseries_definition { + show_legend = false + title = "Memory Utilization" + request { + display_type = "line" + q = "top(avg:docker.mem.in_use{image_name:${var.image_name}} by {container_name}, 10, 'mean', 'desc')" + + style { + line_type = "solid" + line_width = "normal" + palette = "dog_classic" + } + } + yaxis { + include_zero = true + max = "auto" + min = "auto" + scale = "linear" + } + } + } +} + diff --git a/monitors.tf b/monitors.tf new file mode 100644 index 0000000..3e1c010 --- /dev/null +++ b/monitors.tf @@ -0,0 +1,19 @@ +resource "datadog_monitor" "app_monitor" { + name = "Kubernetes Pod Health" + type = "metric alert" + message = "Kubernetes Pods are not in an optimal health state. Notify: @operator" + escalation_message = "Please investigate the Kubernetes Pods, @operator" + + query = "max(last_1m):sum:docker.containers.running{short_image:${var.app_name} <= 1" + + monitor_thresholds { + ok = 3 + warning = 2 + critical = 1 + } + + notify_no_data = true + + tags = ["cfa:${var.cfa_name}", "team:${var.team_name}" "app:${var.app_name}", "env:${var.stage}"] +} + diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/provider.tf b/provider.tf new file mode 100644 index 0000000..93c7b42 --- /dev/null +++ b/provider.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + datadog = { + source = "datadog/datadog" + version = "3.2.0" + } + } +} diff --git a/synthetics.tf b/synthetics.tf new file mode 100644 index 0000000..5fa249d --- /dev/null +++ b/synthetics.tf @@ -0,0 +1,28 @@ +resource "datadog_synthetics_test" "app_sythetics" { + type = "api" + subtype = "http" + + request_definition { + method = "GET" + url = var.url + } + + assertion { + type = "statusCode" + operator = "is" + target = "200" + } + + locations = ["aws:${var.region}"] + options_list { + tick_every = 900 + min_location_failed = 1 + } + + name = "${var.app_name} API check" + message = "Oh no! there seems to be a problem with ${var.app_name} please investigate" + tags = ["cfa:${var.cfa_name}", "team:${var.team_name}" "app:${var.app_name}", "env:${var.stage}"] + + status = "live" +} + diff --git a/terraform.tfvars b/terraform.tfvars new file mode 100644 index 0000000..1859463 --- /dev/null +++ b/terraform.tfvars @@ -0,0 +1,11 @@ +app_namespace = "plaap" +app_name = "blah" +image_name = "name/image" +region = "eu-west-1" +api_key = "2fcc093ed06e4dbe0935433495898cad" +app_key = "aaf4a9654b82cfa8b23b2d65801901a4ad9d35ed" +datadog_site = "https://api.datadoghq.eu/" +aws_profile = "ws-playground-applicatiebeheer" +environment = "test" +prefix_slug = "sanoma" +team = "ws-playground-applicatiebeheer" diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..eb77985 --- /dev/null +++ b/variables.tf @@ -0,0 +1,29 @@ +variable "app_namespace" { + description = "Namespace that the application runs in" + type = string +} + +variable "app_name" { + description = "Name of the application" + type = string +} + +variable "image_name" { + description = "Name of the Docker imagei to use" + type = string +} + +variable "region" { + description = "Defines the AWS region where the resources are located" + type = string +} + +variable "environment" { + description = "Specifies the URL for datadog to monitor" + type = string +} + +variable "url" { + description = "Specifies the URL for datadog to monitor" + type = string +}