AWS integration via CloudFormation
This guide shows how to deploy the Dash0 AWS integration using Terraform's aws_cloudformation_stack resource.
This is not a native Dash0 provider resource. It uses the AWS provider to deploy a CloudFormation stack with the official Dash0 integration template.
The integration provisions the required IAM roles and configuration for collecting telemetry from your AWS account.
When EnableLambdaIntegration or EnableLogGroupInstrumentation is enabled (both default to "true"), the template additionally deploys per-region resources through a CloudFormation StackSet:
- A Kinesis Firehose delivery stream and S3 backup bucket for CloudWatch Logs, which Dash0 uses when you select log groups to forward.
- With
EnableLambdaIntegration: a CloudWatch metric stream, Firehose delivery stream and S3 backup bucket for theAWS/Lambdanamespace, and an EventBridge rule, ApiDestination, and Connection that forward Lambda lifecycle events (UpdateFunctionConfiguration,DeleteFunction) to Dash0 in near real-time.
Prerequisites
- An active Dash0 organization.
- A Dash0 API key (auth token), created under Settings > Auth Tokens in the Dash0 UI.
- Your Dash0 regional endpoint base URL, found under Settings > Endpoints > AWS CloudWatch Metrics in the Dash0 UI (for example
https://ingress.eu-west-1.aws.dash0.com). Provide only the base URL — the template appends the required paths internally. - An AWS account with permissions to create CloudFormation stacks, StackSets, and IAM roles.
- Terraform >= 1.0 and the AWS provider >= 5.0.
- To collect Lambda lifecycle events (enabled by default), a CloudTrail trail logging management events in each region listed in
Regions. Most AWS accounts already have an org-wide trail; if yours does not, either enable one or setEnableLambdaIntegrationto"false".
Example Usage
A complete, runnable example is available in examples/guides/aws_cloudformation_integration/ .
The core resource definition is:
resource "aws_cloudformation_stack" "dash0_integration" {
name = "dash0-integration"
template_url = "https://s3.eu-west-1.amazonaws.com/public-integrations-production.eu-west-1.aws.dash0.com/dash0-customer-integration-cloudformation-v4.yaml"
parameters = {
ApiKey = var.api_key
Dataset = var.dataset
EnableMetricsScraping = var.enable_metrics_scraping
EnableLambdaIntegration = var.enable_lambda_integration
EnableLogGroupInstrumentation = var.enable_log_group_instrumentation
TechnicalId = var.technical_id
Regions = join(",", var.regions)
Dash0RegionalEndpoint = var.dash0_regional_endpoint
}
capabilities = ["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
}This is the v4 template, the same one the Connect AWS wizard in the Dash0 UI launches.
The CAPABILITY_NAMED_IAM capability is required because the template creates named IAM roles for the Dash0 integration.
The CAPABILITY_AUTO_EXPAND capability is required because the template includes a nested AWS::CloudFormation::StackSet that deploys the per-region resources when EnableLambdaIntegration or EnableLogGroupInstrumentation is enabled.
CloudFormation expects Regions to be a CommaDelimitedList, so the Terraform list variable is joined into a comma-separated string before being passed to the stack.
CloudFormation outputs
The integration template exposes the following outputs through aws_cloudformation_stack.dash0_integration.outputs:
| Output | Description | Availability |
|---|---|---|
IntegrationId | UUID of the AWS integration registered in Dash0. Use this as dash0_aws_metric_scrape_config.integration_id. | Always |
ReadOnlyRoleARN | ARN of the read-only IAM role used by Dash0. | Always |
ResourcesInstrumentationRoleARN | ARN of the resources instrumentation IAM role. | When EnableLambdaIntegration or EnableLogGroupInstrumentation is "true" |
RegionalStackSetId | ID of the StackSet that deploys the per-region resources. | When EnableLambdaIntegration or EnableLogGroupInstrumentation is "true" |
TemplateVersion | Version of the deployed onboarding template. | Always |
IntegrationId is the Dash0 integration UUID, not the CloudFormation stack ID, AWS account ID, or TechnicalId IAM external ID.
The output key is case-sensitive.
The example exposes it as a Terraform output:
output "integration_id" {
description = "The Dash0 AWS integration ID."
value = aws_cloudformation_stack.dash0_integration.outputs["IntegrationId"]
}After applying, read it with terraform output -raw integration_id.
For an existing stack, check the Outputs tab in the CloudFormation console for IntegrationId.
If it is missing, update the stack to a template version that exposes this output.
Configure CloudWatch metric scraping with Terraform
Set EnableMetricsScraping to "true" on the stack, then use dash0_aws_metric_scrape_config to choose the namespaces and metrics to collect.
Add the Dash0 provider to your existing required_providers block alongside the AWS provider:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
}
dash0 = {
source = "dash0hq/dash0"
}
}
}
provider "dash0" {}Configure the Dash0 provider with DASH0_API_URL and DASH0_AUTH_TOKEN, as described in the provider configuration documentation .
DASH0_API_URL is the Dash0 API endpoint, not the regional ingress base URL passed to the CloudFormation template.
Use credentials for the same Dash0 organization as the stack's ApiKey.
Reference the stack output directly instead of copying a UUID:
resource "dash0_aws_metric_scrape_config" "prod" {
integration_id = aws_cloudformation_stack.dash0_integration.outputs["IntegrationId"]
aws_metric_scrape_config_yaml = <<-YAML
apiVersion: dash0.com/v1alpha1
kind: Dash0AwsMetricScrapeConfig
spec:
namespaces:
- namespace: AWS/SQS
metrics:
- ApproximateAgeOfOldestMessage
- NumberOfMessagesSent
YAML
}This reference makes Terraform wait for the stack to finish registering the integration before applying its scrape configuration.
No separate depends_on or manual UUID lookup is needed when both resources are in the same configuration.
The scrape configuration belongs to the integration's dataset, selected through the stack's Dataset parameter.
Declare only one scrape configuration per integration, because each apply replaces the complete configuration.
Destroying the scrape configuration stops scraping but does not delete the integration.
If the stack and scrape configuration are managed in separate Terraform configurations, expose integration_id from the stack configuration and pass that value to the configuration managing dash0_aws_metric_scrape_config.
Apply the stack configuration first, because Terraform does not infer dependencies across separate states.
CloudFormation Parameters
| Parameter | Description | Required | Default |
|---|---|---|---|
ApiKey | Dash0 API key (auth token) for the integration. | Yes | -- |
Dataset | The Dash0 dataset to send telemetry data to. | No | default |
EnableMetricsScraping | Let Dash0 read CloudWatch metrics and resource tags in the selected regions ("true" or "false"). | No | "true" |
EnableLambdaIntegration | Enable the Lambda instrumentation role, stream AWS/Lambda metrics, and forward Lambda lifecycle events (UpdateFunctionConfiguration, DeleteFunction) to Dash0 via EventBridge ("true" or "false"). Lifecycle events require a CloudTrail trail logging management events in the selected regions. | No | "true" |
EnableLogGroupInstrumentation | Let Dash0 manage CloudWatch Logs subscription filters in the selected regions, using a per-region logs Firehose ("true" or "false"). Enabling it does not forward any logs: you select log groups separately in the integration's Logs tab. Remove Dash0-managed subscriptions before disabling it, because disabling removes the roles and permissions but not existing subscriptions. | No | "true" |
TechnicalId | External ID for securing IAM role assumption. When empty, the template uses the CloudFormation stack ID automatically — the recommended approach for IaC onboarding. | No | "" |
Regions | Comma-separated list of AWS regions Dash0 covers, and in which the StackSet deploys its per-region resources (for example eu-west-1,us-east-1). | Yes | -- |
Dash0RegionalEndpoint | Regional Dash0 ingress endpoint base URL for your organization. Find it under Settings > Endpoints > AWS CloudWatch Metrics in the Dash0 UI (for example https://ingress.eu-west-1.aws.dash0.com). Provide only the base URL; the template appends the required paths internally. | Yes | -- |
Getting Started
-
Copy the example directory into your project, or use the resource definition above in your own configuration.
-
Create a
terraform.tfvarsfile with your values (do not commit this file):api_key = "your-dash0-auth-token" dash0_regional_endpoint = "https://ingress.eu-west-1.aws.dash0.com" regions = ["eu-west-1"] -
Initialize and apply:
terraform init terraform plan terraform apply -
To tear down the integration:
terraform destroy
Avoid repeated API-key changes
CloudFormation hides the integration's API key when Terraform reads the stack, returning **** instead of the token.
As a result, Terraform can report an API-key change even when you have not changed the token.
This is a known AWS provider issue .
To suppress this change during routine applies, add the following block inside aws_cloudformation_stack.dash0_integration:
lifecycle {
ignore_changes = [parameters["ApiKey"]]
}This rule suppresses the API-key diff, not changes to the rest of the stack. It also prevents Terraform from applying a new API key, including one updated in Secrets Manager.
Before applying any change to this stack, temporarily remove the API-key ignore rule and supply a valid token. Otherwise, Terraform can send the masked value **** as the API key and the update can fail. This applies to region changes, tags, template updates, and token rotation.
Update the stack: add a region
Use this sequence whenever you need to update a stack that has the ignore rule above.
For example, to add eu-central-1 while keeping eu-west-1:
-
Temporarily remove the API-key ignore rule. Remove
parameters["ApiKey"]fromignore_changes. If it is the only entry, remove the entirelifecycleblock shown above. Do not removeApiKeyfrom theparametersmap. -
Make sure Terraform has a valid API key. Check the value supplied through
api_keyor your secret source, such as Secrets Manager. Use the actual token, not the masked value****. -
Add the region to your configuration. Keep the existing regions and append the new one:
regions = ["eu-west-1", "eu-central-1"] -
Review a fresh plan. Do not reuse a plan saved before removing the ignore rule.
terraform planExpect an in-place update to
Regionsand an API-key change, which Terraform normally hides as a sensitive value. The API-key change is expected even if you are reusing the same valid token. -
Apply and verify the update.
terraform applyWait for the parent CloudFormation stack to reach
UPDATE_COMPLETE. If the Lambda integration or log-group instrumentation is enabled, also check that the StackSet instance in the added region isCURRENTwith a detailed status ofSUCCEEDED. -
Restore the API-key ignore rule. Add the
lifecycleblock above back to the stack resource, then check the plan again:terraform planWith no other configuration changes, Terraform should now report no changes to this stack. Keep this rule in your configuration for routine applies, and remove it again before the next stack update.
Rotate the API key
Follow the same sequence, but replace the token in step 2 instead of changing the regions in step 3. Keep the old token valid until the stack update completes and you have verified that the integration works with the replacement. Then revoke the old token and restore the ignore rule. Updating the token in Secrets Manager alone does not update the integration while the rule is enabled.
Notes
- The
api_keyvariable is marked assensitiveso Terraform will not display its value in plan or apply output. - The
TechnicalIdparameter is optional. When omitted or left empty, the template derives the IAM external ID from the CloudFormation stack ID. This is the recommended approach for Terraform onboarding — no Dash0-internal identifier is required. - The CloudFormation stack is region-specific.
Deploy it in the region where your AWS workloads run, or in the region closest to your Dash0 environment.
The
Regionsparameter controls which regions the nested StackSet deploys its per-region resources into; it is independent from the region the parent stack itself is deployed in. - The S3 backup buckets created by the StackSet are retained on
terraform destroyby design. Delete them manually if you want to fully reclaim the bucket names before re-onboarding. - To move an existing stack from the v3 template, change
template_urland follow Update the stack: the update is a stack change like any other. The v4 template addsEnableLogGroupInstrumentation, which defaults to"true"; set it to"false"to keep the stack's previous resources.
Last updated: