The Datadog Terraform module for Container Apps wraps the azurerm_container_app resource and automatically configures your Azure Container App for Datadog Serverless Monitoring by adding required environment variables and the serverless-init sidecar.
If you don’t already have Terraform set up, install Terraform, create a new directory, and make a file called main.tf.
Then, add the following to your Terraform configuration, updating it as necessary based on your needs:
variable "datadog_api_key" {
description = "Your Datadog API key"
type = string
sensitive = true
}
provider "azurerm" {
features {}
subscription_id = "00000000-0000-0000-0000-000000000000" // Replace with your subscription ID
}
resource "azurerm_container_app_environment" "my_env" {
name = "my-container-app-env" // Replace with your container app environment name
resource_group_name = "my-resource-group" // Replace with your resource group name
location = "eastus"
}
module "my_container_app" {
source = "DataDog/container-app-datadog/azurerm"
version = "~> 1.0"
name = "my-container-app" // Replace with your container app name
resource_group_name = "my-resource-group" // Replace with your resource group name
container_app_environment_id = azurerm_container_app_environment.my_env.id
datadog_api_key = var.datadog_api_key
datadog_site = "datadoghq.com" // Replace with your Datadog site
datadog_service = "my-service" // Replace with your service name
datadog_env = "dev" // Replace with your environment (e.g. prod, staging, dev)
datadog_version = "0.1.0" // Replace with your application version
revision_mode = "Single"
workload_profile_name = "Consumption"
ingress = {
external_enabled = true
target_port = 8080
traffic_weight = [{
percentage = 100
latest_revision = true
}]
}
template = {
container = [{
cpu = 0.5
memory = "1Gi"
image = "docker.io/your-docker-image:latest" // Replace with your Docker image
name = "main"
}]
}
}
Finally, run terraform apply, and follow any prompts.
The Datadog Container App module only deploys the Container App resource, so you need to build and push your container separately.
See the Environment Variables for more information on the configuration options available through the env.
Ensure the container port for the main container is the same as the one exposed in your Dockerfile/service.
If you haven’t already, initialize your Terraform project:
To deploy your app, run:
Application environment variables
Because Azure Container Apps is built on Kubernetes, you cannot share environment variables between containers.
| Name | Description |
|---|
DD_SERVICE | How you want to tag your service. For example, sidecar-azure. |
DD_ENV | How you want to tag your env. For example, prod. |
DD_VERSION | How you want to tag your application version. |
Sidecar container
- In the Azure Portal, navigate to Application > Revisions and replicas. Select Create new revision.
- On the Container tab, under Container image, select Add. Choose App container.
- In the Add a container form, provide the following:
- Name:
datadog - Image source: Docker Hub or other registries
- Image type:
Public - Registry login server:
docker.io - Image and tag:
datadog/serverless-init:latest - Define your container resource allocation based on your usage.
- Add a volume mount using replica-scoped storage. Use type “Ephemeral storage” when creating your volume. Ensure that the name and mount path matches the mount you configured in the application container.
- Set the environment variables in the following table:
Sidecar Environment variables
| Name | Description |
|---|
DD_AZURE_SUBSCRIPTION_ID | Required. Your Azure subscription ID. |
DD_AZURE_RESOURCE_GROUP | Required. Your Azure resource group. |
DD_API_KEY | Required. Your Datadog API key. |
DD_SITE | Your Datadog site. For example, datadoghq.com. |
DD_SERVICE | How you want to tag your service. For example, sidecar-azure. |
DD_ENV | How you want to tag your env. For example, prod. |
DD_VERSION | How you want to tag your application version. |
DD_SERVERLESS_LOG_PATH | If using the agent for log collection, where you write your logs. For example, /LogFiles/*.log. This must match the logging path set up in Application |
Logging
If using the Datadog Agent for log collection, add a volume mount to the sidecar container and your application containers using replica-scoped storage. Use type Ephemeral storage when creating your volume. The examples on this page use the volume name logs and the mount path /LogFiles.
