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
3 changes: 2 additions & 1 deletion docs/data-sources/metric_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ output "metric_integration_ids" {
```

### Further Examples
- [Metric Integration Examples](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration)
- [Header-based](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration/header) — export using header-based authentication.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export what? try to provide a title that leaves no room for the reader or llm to guess what you mean.

- [OAuth 2.0](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration/oauth) — export using OAuth 2.0 authentication.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export what? see above.


<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/metric_integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ output "metric_integration_ids" {
```

### Further Examples
- [Metric Integration Examples](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration)
- [Header-based](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration/header) — export using header-based authentication.
- [OAuth 2.0](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration/oauth) — export using OAuth 2.0 authentication.

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/metric_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ output "metric_integration_ids" {
```

### Further Examples
- [Metric Integration Examples](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration)
- [Header-based](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration/header) — export using header-based authentication.
- [OAuth 2.0](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.18.0/examples/mongodbatlas_metric_integration/oauth) — export using OAuth 2.0 authentication.

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
68 changes: 10 additions & 58 deletions examples/mongodbatlas_metric_integration/README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
# MongoDB Atlas Metric Integration with Datadog Example
# MongoDB Atlas Metric Integration Examples

This example demonstrates how to configure a metric integration to export MongoDB Atlas metrics to Datadog over OTLP. It also shows how to read the integration back with the singular and plural data sources.
Configure a metric integration to export Atlas metrics to an OTLP-compatible endpoint, using header-based or OAuth 2.0 authentication.

This example is specific to Datadog. To export to another provider, update `provider_type` (`CUSTOM`, `NEW_RELIC`, or `DYNATRACE`), the `endpoint`, and the authentication `headers` to match that provider.
## Sibling examples

## Prerequisites
Header-based:

- MongoDB Atlas Service Account with Organization Owner or Project Owner role.
- An OTLP-compatible endpoint URL and authentication credentials. This example uses Datadog and creates the Datadog API key with the `datadog` provider. For more information on OTLP providers, see: [MongoDB Atlas - OTel Integration](https://www.mongodb.com/docs/atlas/tutorial/otel-integration/) Documentation.
- [`header/`](header/README.md) — export to Datadog using header-based authentication (creates the Datadog API key with the `datadog` provider).

## Resources Created
OAuth 2.0:

This example creates the following resources:
- [`oauth/client_secret/`](oauth/client_secret/README.md) — export using a shared client secret.
- [`oauth/private_key_jwt/`](oauth/private_key_jwt/README.md) — export using an Atlas-managed private-key JWT signing assertion; register the returned `jwks_uri` with your identity provider.

- MongoDB Atlas Project
- MongoDB Atlas Metric Integration
- Datadog API key
Each example creates a MongoDB Atlas project and the metric integration resource, and reads it back with the singular and plural data sources.

## Usage

**1\. Ensure your MongoDB Atlas and Datadog credentials are set up.**

Set the following environment variables:

```bash
export MONGODB_ATLAS_CLIENT_ID="<ATLAS_CLIENT_ID>"
export MONGODB_ATLAS_CLIENT_SECRET="<ATLAS_CLIENT_SECRET>"
export DD_API_KEY="<DATADOG_API_KEY>"
export DD_APP_KEY="<DATADOG_APP_KEY>"
```

Alternatively, follow as in the `variables.tf` file and create a **terraform.tfvars** file with all the variable values:

```hcl
atlas_org_id = "your-org-id"
atlas_client_id = "your-service-account-client-id"
atlas_client_secret = "your-service-account-client-secret"
datadog_api_key = "your-datadog-api-key"
datadog_app_key = "your-datadog-app-key"
datadog_endpoint = "https://otlp.datadoghq.com/v1/metrics"
```

**2\. Review the Terraform plan.**

Execute the following command and confirm the plan's accuracy.

```bash
terraform plan
```

**3\. Execute the Terraform apply.**

Execute the plan to provision the resources.

```bash
terraform apply
```

**4\. Destroy the resources.**

When you have finished your testing, ensure you destroy the resources to avoid accruing charges in Atlas.

```bash
terraform destroy
```
For product limits and supported providers, see the [resource documentation](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/metric_integration) and [MongoDB Atlas - OTel Integration](https://www.mongodb.com/docs/atlas/tutorial/otel-integration/) Documentation.
66 changes: 66 additions & 0 deletions examples/mongodbatlas_metric_integration/header/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# MongoDB Atlas Metric Integration with Datadog Example

This example demonstrates how to configure a metric integration to export MongoDB Atlas metrics to Datadog over OTLP. It also shows how to read the integration back with the singular and plural data sources.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a metric integration that exports ....

new paragraph:
The example also shows ....


This example is specific to Datadog. To export to another provider, update `provider_type` (`CUSTOM`, `NEW_RELIC`, or `DYNATRACE`), the `endpoint`, and the authentication `headers` to match that provider.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To export what? metrics? Add this

add "the values for that provider", as in:
... to match the values for that provider.


## Prerequisites

- MongoDB Atlas Service Account with Organization Owner or Project Owner role.
- An OTLP-compatible endpoint URL and authentication credentials. This example uses Datadog and creates the Datadog API key with the `datadog` provider. For more information on OTLP providers, see: [MongoDB Atlas - OTel Integration](https://www.mongodb.com/docs/atlas/tutorial/otel-integration/) Documentation.

## Resources Created

This example creates the following resources:

- MongoDB Atlas Project
- MongoDB Atlas Metric Integration
- Datadog API key

## Usage

**1\. Ensure your MongoDB Atlas and Datadog credentials are set up.**

Set the following environment variables:

```bash
export MONGODB_ATLAS_CLIENT_ID="<ATLAS_CLIENT_ID>"
export MONGODB_ATLAS_CLIENT_SECRET="<ATLAS_CLIENT_SECRET>"
export TF_VAR_datadog_api_key="<DATADOG_API_KEY>"
export TF_VAR_datadog_app_key="<DATADOG_APP_KEY>"
```

Alternatively, follow as in the `variables.tf` file and create a **terraform.tfvars** file with all the variable values:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean: Alternatively, specify all the variable values in a single file, as shown in the following example of the variables.tf file:

If yes, please consider rewriting this


```hcl
atlas_org_id = "your-org-id"
atlas_client_id = "your-service-account-client-id"
atlas_client_secret = "your-service-account-client-secret"
datadog_api_key = "your-datadog-api-key"
datadog_app_key = "your-datadog-app-key"
datadog_endpoint = "https://otlp.datadoghq.com/v1/metrics"
```

**2\. Review the Terraform plan.**

Execute the following command and confirm the plan's accuracy.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run the following command and ...


```bash
terraform plan
```

**3\. Execute the Terraform apply.**

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere: Run is much shorter than execute. consider replacing all literal instruction text instances of execute with run. The scope is just this PR, don't expand scope. This can be gradually adopted as the practice over time.
This is just a suggestion and is optional.


Execute the plan to provision the resources.

```bash
terraform apply
```

**4\. Destroy the resources.**

When you have finished your testing, ensure you destroy the resources to avoid accruing charges in Atlas.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the sentence at least, suggest to use you delete... instead of destroy


```bash
terraform destroy
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# OAuth 2.0 client-secret metric integration

Export Atlas metrics to an OTLP-compatible endpoint using OAuth 2.0 client-secret authentication.

For product limits, see the [resource documentation](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/metric_integration#limitations).

## Prerequisites

- MongoDB Atlas Service Account with Organization Owner or Project Owner role.
- An OTLP-compatible endpoint URL.
- OAuth 2.0 client credentials (`client_id` and `client_secret`) registered with your identity provider's token endpoint.

## Defaults

Omit optional variables to use these values from `variables.tf`:

- `metric_selection`: `["ATLAS_STREAM_PROCESSING"]`
- `oauth_scopes`: `[]` — no scopes requested
- `atlas_project_name`: `tf-metric-integration-oauth-client-secret`

## Usage

**1. Set credentials.**

```bash
export MONGODB_ATLAS_CLIENT_ID="<ATLAS_CLIENT_ID>"
export MONGODB_ATLAS_CLIENT_SECRET="<ATLAS_CLIENT_SECRET>"
```

**2. Create `terraform.tfvars`.**

Required inputs:

```hcl
atlas_org_id = "your-org-id"
atlas_client_id = "your-service-account-client-id"
atlas_client_secret = "your-service-account-client-secret"
otel_endpoint = "https://otel-collector.example.com:4318/v1/metrics"
token_endpoint = "https://idp.example.com/oauth2/token"
client_id = "your-oauth-client-id"
client_secret = "your-oauth-client-secret"

# metric_selection = ["ATLAS_STREAM_PROCESSING"] # default
# oauth_scopes = ["metrics.write"] # optional
```

**3. Plan and apply.**

```bash
terraform plan
terraform apply
```

**4. Destroy.**

```bash
terraform destroy
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Export Atlas metrics to an OTLP-compatible endpoint using OAuth 2.0 client-secret authentication.
resource "mongodbatlas_project" "this" {
name = var.atlas_project_name
org_id = var.atlas_org_id
}

resource "mongodbatlas_metric_integration" "this" {
project_id = mongodbatlas_project.this.id
integration_type = "OTEL"
provider_type = "CUSTOM"
auth_type = "OAUTH2"
aggregation_temporality = "DELTA"
endpoint = var.otel_endpoint
metric_selection = var.metric_selection

oauth = {
client_auth_method = "CLIENT_SECRET"
token_endpoint = var.token_endpoint
client_id = var.client_id
client_secret = var.client_secret
scopes = var.oauth_scopes
}
}

data "mongodbatlas_metric_integration" "this" {
project_id = mongodbatlas_metric_integration.this.project_id
metric_integration_id = mongodbatlas_metric_integration.this.metric_integration_id
}

data "mongodbatlas_metric_integrations" "this" {
project_id = mongodbatlas_metric_integration.this.project_id
depends_on = [mongodbatlas_metric_integration.this]
}

output "metric_integration_type" {
description = "Type of the metric integration."
value = data.mongodbatlas_metric_integration.this.integration_type
}

output "metric_integration_ids" {
description = "IDs of the metric integrations in the project."
value = [for r in data.mongodbatlas_metric_integrations.this.results : r.metric_integration_id]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "mongodbatlas" {
client_id = var.atlas_client_id
client_secret = var.atlas_client_secret
Comment on lines +2 to +3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
variable "atlas_client_id" {
description = "Atlas Service Account Client ID"
type = string
default = ""
}

variable "atlas_client_secret" {
description = "Atlas Service Account Client Secret"
type = string
sensitive = true
default = ""
}

variable "atlas_org_id" {
description = "Atlas Organization ID"
type = string
}

variable "atlas_project_name" {
description = "Name of the Atlas project"
type = string
default = "tf-metric-integration-oauth-client-secret"
}

variable "otel_endpoint" {
description = "OTLP-compatible endpoint URL for metric ingestion"
type = string
}

variable "metric_selection" {
description = "Array of metric categories to export"
type = list(string)
default = ["ATLAS_STREAM_PROCESSING"]
}

variable "token_endpoint" {
description = "OAuth 2.0 token endpoint URL"
type = string
}

variable "client_id" {
description = "OAuth 2.0 client identifier registered with the token endpoint"
type = string
}

variable "client_secret" {
description = "OAuth 2.0 client secret"
type = string
sensitive = true
}

variable "oauth_scopes" {
description = "OAuth 2.0 scopes requested on the token"
type = list(string)
default = []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
}
}
required_version = ">= 1.10"
}
Loading
Loading