Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion datadog/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
.terraform
*tfstate*
*tfstate*

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
*.tfvars

# Ignore lock files
.terraform.lock.hcl
24 changes: 16 additions & 8 deletions datadog/setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.39.0"
version = "3.57.0"
}
}

required_version = "~>0.13"
}

provider "google" {
project = var.project
zone = var.zone
}

Expand All @@ -18,12 +19,23 @@ variable "dd_api_key" {
description = "Datadog Agent API key"
}

variable "project" {
type = string
description = "GCP Project"
}

variable "zone" {
type = string
description = "GCP Zone to deploy"
default = "us-east1-b"
}

variable "network" {
type = string
description = "GCP VCP to deploy"
default = "default"
}

variable "enable_firewall_rule" {
type = bool
description = "Creates firewall rule to allow public traffic"
Expand All @@ -36,14 +48,10 @@ variable "fix_frontend" {
default = true
}

data "google_compute_network" "default" {
name = "default"
}

resource "google_compute_firewall" "ecommerce" {
count = var.enable_firewall_rule ? 1 : 0
name = "allow-ecommerce"
network = "default"
network = var.network

allow {
protocol = "tcp"
Expand Down Expand Up @@ -73,7 +81,7 @@ resource "google_compute_instance" "ecommerce" {
}

network_interface {
network = "default"
network = var.network

access_config {
nat_ip = google_compute_address.ecommerce.address
Expand All @@ -86,7 +94,7 @@ resource "google_compute_instance" "ecommerce" {
}

metadata_startup_script = <<EOT
cd /root/ecommerce-workshop/docker-compose-files
cd /root/ecommerce-workshop/deploy/docker-compose
POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres DD_API_KEY=${var.dd_api_key} docker-compose -f docker-compose-${local.docker_compose}-instrumented.yml up -d
systemctl start gor
EOT
Expand Down
7 changes: 5 additions & 2 deletions datadog/setup/packer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ check-variables:
ifndef PROJECT
$(error PROJECT is undefined)
endif
ifndef ZONE
$(error ZONE is undefined)
endif

build: check-variables
packer build -var 'project_id=${PROJECT}' -var 'zone=${ZONE}' packer.json
packer build -var 'project_id=${PROJECT}' -var 'zone=${ZONE}' -var 'network=$(or $(NETWORK),default)' packer.json

force-build: check-variables
packer build -force -var 'project_id=${PROJECT}' -var 'zone=${ZONE}' packer.json
packer build -force -var 'project_id=${PROJECT}' -var 'zone=${ZONE}' -var 'network=$(or $(NETWORK),default)' packer.json
8 changes: 4 additions & 4 deletions datadog/setup/packer/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ apt-get update

apt-get -y install docker-ce

curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

apt-get -y install git wget

git clone https://github.com/DataDog/ecommerce-workshop.git

curl -L https://github.com/buger/goreplay/releases/download/v1.0.0/gor_1.0.0_x64.tar.gz -o gor_1.0.0_x64.tar.gz
tar -xf gor_1.0.0_x64.tar.gz
curl -L https://github.com/buger/goreplay/releases/download/v1.2.0/gor_v1.2.0_x64.tar.gz -o gor_v1.2.0_x64.tar.gz
tar -xf gor_v1.2.0_x64.tar.gz
mv gor /usr/local/bin/gor
rm -rf gor_1.0.0_x64.tar.gz
rm -rf gor_v1.2.0_x64.tar.gz

systemctl disable gor
4 changes: 3 additions & 1 deletion datadog/setup/packer/packer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"variables": {
"project_id": "",
"zone": ""
"zone": "",
"network": "default"
},
"builders": [
{
"type": "googlecompute",
"project_id": "{{user `project_id`}}",
"source_image_family": "ubuntu-1804-lts",
"zone": "{{user `zone`}}",
"network": "{{user `network`}}",
"ssh_username": "root",
"image_name": "datadog-ecommerce",
"image_labels": {
Expand Down