Skip to content

Commit

Permalink
Merge pull request #343 from jdno/datadog-fastly
Browse files Browse the repository at this point in the history
Deploy Datadog integration for Fastly account
  • Loading branch information
jdno authored Sep 11, 2023
2 parents 0a62555 + 71006f9 commit d24e1f3
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 1 deletion.
69 changes: 69 additions & 0 deletions terragrunt/accounts/legacy/datadog-fastly/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions terragrunt/accounts/legacy/datadog-fastly/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
terraform {
source = "../../../modules//datadog-fastly"
}

include {
path = find_in_parent_folders()
merge_strategy = "deep"
}

inputs = {
services = {
"5qaYFyyiorVua6uCZg7It0" = {
env = "staging"
app = "releases"
service = "dev-static-rust-lang-org"
},
"gEfRWQihVaQqh6vsPlY0H1" = {
env = "prod"
app = "crates-io"
service = "static-crates-io"
},
"MWlq3AIDXubpbw725c7og3" = {
env = "prod"
app = "releases"
service = "static-rust-lang-org"
},
"liljrvY3Xt0CzNk0mpuLa7" = {
env = "staging"
app = "crates-io"
service = "static-staging-crates-io"
},
}
}
2 changes: 1 addition & 1 deletion terragrunt/accounts/legacy/releases-prod/deployed-ref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
51b9ceee5db8ed60e1f86d1acd0231a7a2a2ba81
04334ff7f9612c5a945e3b043b6c62c552f3c12c
18 changes: 18 additions & 0 deletions terragrunt/modules/datadog-fastly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Fastly Integration for Datadog

[Datadog] is a monitoring and observability platform that we use to monitor
our cloud infrastructure. Datadog provides an
[integration for Fastly][datadog-fastly] and a [Terraform module] to manage it,
which we use in this module.

We use [tags](https://docs.datadoghq.com/getting_started/tagging/) to make it
easy to filter and group metrics in Datadog. Each Fastly service is tagged with
the following variables:

- `env`: The environment of the service, either `prod` or `staging`
- `app`: The app or component that this service belongs to, e.g. `crates-io`
- `service`: The name of the service, e.g. `static-crates-io`

[datadog]: https://datadoghq.com
[datadog-fastly]: https://docs.datadoghq.com/integrations/fastly
[terraform module]: https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/integration_fastly_account
21 changes: 21 additions & 0 deletions terragrunt/modules/datadog-fastly/_terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_version = "~> 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.32"
}
datadog = {
source = "datadog/datadog"
version = "3.28.0"
}
fastly = {
source = "fastly/fastly"
version = "5.2.2"
}
}
}

provider "datadog" {}
provider "fastly" {}
22 changes: 22 additions & 0 deletions terragrunt/modules/datadog-fastly/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data "aws_ssm_parameter" "fastly_api_key" {
name = "/prod/datadog-fastly/fastly-api-key"
with_decryption = false
}

resource "datadog_integration_fastly_account" "account" {
name = "Rust Foundation"
api_key = data.aws_ssm_parameter.fastly_api_key.value
}

resource "datadog_integration_fastly_service" "service" {
for_each = var.services

account_id = datadog_integration_fastly_account.account.id
service_id = each.key

tags = [
"env:${each.value.env}",
"app:${each.value.app}",
"service:${each.value.service}",
]
}
Empty file.
17 changes: 17 additions & 0 deletions terragrunt/modules/datadog-fastly/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "services" {
description = "List of Fastly services"
type = map(object({
env = string
app = string
service = string
}))
default = {}

validation {
condition = alltrue([
for e in var.services :
contains(["staging", "prod"], e.env)
])
error_message = "The environment must be 'staging' or 'prod'."
}
}
4 changes: 4 additions & 0 deletions terragrunt/modules/release-distribution/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ data "aws_s3_bucket" "logs" {
bucket = var.log_bucket
}

data "aws_ssm_parameter" "datadog_api_key" {
name = "/${var.environment}/promote-release/datadog-api-key"
}

data "aws_ssm_parameter" "fastly_customer_id" {
name = "/${var.environment}/promote-release/fastly-customer-id"
with_decryption = false
Expand Down
5 changes: 5 additions & 0 deletions terragrunt/modules/release-distribution/fastly-static.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ resource "fastly_service_vcl" "static" {
VCL
}

logging_datadog {
name = "datadog"
token = data.aws_ssm_parameter.datadog_api_key.value
}

logging_s3 {
name = "s3-request-logs"
bucket_name = data.aws_s3_bucket.logs.bucket
Expand Down

0 comments on commit d24e1f3

Please sign in to comment.