Skip to content

Commit aafc899

Browse files
committed
adding datadog aws
1 parent 25929e4 commit aafc899

File tree

5 files changed

+225
-0
lines changed

5 files changed

+225
-0
lines changed

datadog_v2/kickstarter/terraform/aws/.terraform.lock.hcl

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# AWS Configuration
2+
aws_region = "us-east-1"
3+
aws_ami_id = "ami-0abcdef1234567890" # Ubuntu 20.04 LTS AMI ID for your region
4+
aws_key_name = "my-key-pair"
5+
6+
# Network Configuration
7+
vpc_name = "my-vpc"
8+
subnet_name = "my-subnet"
9+
aws_security_group_name = "my-security-group"
10+
11+
# SSH Configuration
12+
ssh_private_key = "~/.ssh/my-key-pair.pem"
13+
14+
# Datadog Configuration
15+
datadog_site = "datadoghq.com" # or datadoghq.eu for EU
16+
datadog_api_key = "your-datadog-api-key-here"
17+
datadog_integration_name = "redis_enterprise_prometheus" # default value
18+
19+
# Redis Configuration
20+
redis_fqdn = "your-redis-cluster.example.com"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
init_config:
2+
3+
instances:
4+
5+
- openmetrics_endpoint: https://${REDIS_FQDN}:8070/v2
6+
tls_verify: false
7+
type_overrides:
8+
endpoint_client_connections: gauge
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5.0"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
region = var.aws_region
12+
}
13+
14+
data "aws_vpc" "aws_vpc" {
15+
filter {
16+
name = "tag:Name"
17+
values = [var.vpc_name]
18+
}
19+
}
20+
21+
data "aws_subnet" "aws_subnet" {
22+
filter {
23+
name = "tag:Name"
24+
values = [var.subnet_name]
25+
}
26+
}
27+
28+
data "aws_security_group" "aws_security_group" {
29+
filter {
30+
name = "tag:Name"
31+
values = [var.aws_security_group_name]
32+
}
33+
}
34+
35+
resource "aws_instance" "datadog_agent_vm" {
36+
ami = var.aws_ami_id
37+
instance_type = "t3.medium"
38+
key_name = var.aws_key_name
39+
subnet_id = data.aws_subnet.aws_subnet.id
40+
vpc_security_group_ids = [data.aws_security_group.aws_security_group.id]
41+
42+
tags = {
43+
Name = "datadog-agent-vm"
44+
}
45+
}
46+
47+
resource "null_resource" "install_datadog_agent" {
48+
connection {
49+
type = "ssh"
50+
host = aws_instance.datadog_agent_vm.public_ip
51+
user = "ubuntu"
52+
private_key = file(var.ssh_private_key)
53+
}
54+
55+
provisioner "remote-exec" {
56+
inline = [
57+
"DD_API_KEY=${var.datadog_api_key} DD_SITE=\"${var.datadog_site}\" bash -c \"$(curl -L https://install.datadoghq.com/scripts/install_script_agent7.sh)\"",
58+
"git clone https://github.com/redis-field-engineering/datadog-integrations-extras",
59+
"sudo apt update",
60+
"sudo apt install -y software-properties-common",
61+
"sudo add-apt-repository ppa:deadsnakes/ppa -y",
62+
"sudo apt update",
63+
"sudo apt install -y python3.12 python3.12-venv python3.12-dev",
64+
"python3.12 -m venv venv",
65+
". venv/bin/activate",
66+
"pip install build",
67+
"cd datadog-integrations-extras",
68+
"git checkout v2-metrics-extended",
69+
"cd ${var.datadog_integration_name}",
70+
"python3.12 -m build --wheel",
71+
"sudo datadog-agent integration install -r -w ./dist/datadog_redis_enterprise_prometheus-2.0.1-py3-none-any.whl",
72+
]
73+
}
74+
75+
provisioner "file" {
76+
source = "config.yaml.example"
77+
destination = "conf.yaml.template"
78+
}
79+
80+
provisioner "remote-exec" {
81+
inline = [
82+
"sudo apt-get update && sudo apt-get install -y gettext-base",
83+
"export REDIS_FQDN=${var.redis_fqdn}",
84+
"envsubst < conf.yaml.template > conf.yaml",
85+
"sudo cp conf.yaml /etc/datadog-agent/conf.d/redis_enterprise_prometheus.d/conf.yaml",
86+
"sudo systemctl restart datadog-agent"
87+
]
88+
}
89+
90+
depends_on = [aws_instance.datadog_agent_vm]
91+
}
92+
93+
output "instance_ip" {
94+
description = "Public IP address of the Datadog agent instance"
95+
value = aws_instance.datadog_agent_vm.public_ip
96+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
variable "aws_region" {
2+
description = "AWS region for deployment"
3+
type = string
4+
}
5+
6+
variable "aws_ami_id" {
7+
description = "Ubuntu 20.04 LTS AMI ID for the region"
8+
type = string
9+
}
10+
11+
variable "aws_key_name" {
12+
description = "EC2 Key Pair name for SSH access"
13+
type = string
14+
}
15+
16+
variable "vpc_name" {
17+
description = "VPC name (looked up by tag:Name)"
18+
type = string
19+
}
20+
21+
variable "subnet_name" {
22+
description = "Subnet name (looked up by tag:Name)"
23+
type = string
24+
}
25+
26+
variable "aws_security_group_name" {
27+
description = "Security group name (looked up by tag:Name)"
28+
type = string
29+
}
30+
31+
variable "ssh_private_key" {
32+
description = "Path to SSH private key file"
33+
type = string
34+
}
35+
36+
variable "datadog_site" {
37+
description = "Datadog site"
38+
type = string
39+
sensitive = true
40+
}
41+
42+
variable "datadog_api_key" {
43+
description = "Datadog API key"
44+
type = string
45+
sensitive = true
46+
}
47+
48+
variable "datadog_integration_name" {
49+
description = "Name of the Datadog integration to install"
50+
type = string
51+
default = "redis_enterprise_prometheus"
52+
}
53+
54+
variable "redis_fqdn" {
55+
description = "The fully qualified domain name (FQDN) of the Redis cluster"
56+
type = string
57+
}

0 commit comments

Comments
 (0)