Skip to content

Conversation

EspenAlbert
Copy link
Collaborator

@EspenAlbert EspenAlbert commented Aug 25, 2025

Description

Adds provider_meta support to the provider

Link to any related issue(s): CLOUDP-340210

Example usage

Terraform code main.tf

terraform {
  required_version = ">=1.11"
  required_providers {
    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "~>1.39"
    }
  }
  provider_meta "mongodbatlas" {
    module_name = "root-module" # variables may not be used here. Can always be sent.
  }
}

provider "mongodbatlas" {}

variable "org_id" {
  type    = string
  default = "65def6ce0f722a1507105aa5"
}

resource "mongodbatlas_project" "this" {
  org_id = var.org_id
  name   = "analytics_test"
}

module "project_module" {
  source = "./modules/project"
  org_id = var.org_id
}


resource "mongodbatlas_custom_db_role" "create_role" {
  project_id = mongodbatlas_project.this.id
  role_name  = "my_custom_role"

  actions {
    action = "UPDATE"
    resources {
      database_name = "myDb"
    }
  }
}

Terraform code modules/project/main.tf

terraform {
  required_version = ">=1.11"
  required_providers {
    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "~>1.39"
    }
  }
  provider_meta "mongodbatlas" {
    # script_location = "my-internal-module"
    module_name = "cluster-lz"
    module_version = "0.1.1"
  }
}

variable "org_id" {
  type = string
}

resource "mongodbatlas_project" "this" {
  org_id = var.org_id
  name   = "analytics_test_in_module"
}

Logs example terraform plan (see Name/project and Name/custom_db_role)

2025-08-26T10:35:34.483+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:35:34.483+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:35:35.491+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:35:35.581+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:35:35.840+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:35:35.919+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:35:36.341+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:35:36.427+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:35:36.711+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:35:36.786+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:35:37.073+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:35:37.143+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:35:37.449+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/false ModuleName/root-module Name/custom_db_role Operation/read

Logs example terraform apply

2025-08-26T10:39:40.560+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:39:40.560+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:39:41.266+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:39:41.372+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:39:41.659+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:39:41.717+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:39:42.191+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:39:42.244+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:39:42.563+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:39:42.598+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:39:42.911+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/read
2025-08-26T10:39:42.954+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/read
2025-08-26T10:39:43.280+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/false ModuleName/root-module Name/custom_db_role Operation/read
2025-08-26T10:39:49.229+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update
2025-08-26T10:39:49.229+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:50.409+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update
2025-08-26T10:39:50.447+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:50.774+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update
2025-08-26T10:39:50.797+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:51.167+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:51.285+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update
2025-08-26T10:39:51.545+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:51.654+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update
2025-08-26T10:39:51.917+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:52.026+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update
2025-08-26T10:39:52.441+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:52.534+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update
2025-08-26T10:39:52.805+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:52.889+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update
2025-08-26T10:39:53.167+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/root-module Name/project Operation/update
2025-08-26T10:39:53.334+0100 [DEBUG] provider.terraform-provider-mongodbatlas: User-Agent: terraform-provider-mongodbatlas/1.40.0-13-gb4a633345 Terraform/1.11.0-alpha20250107 AdvancedClusterPreview/true ModuleName/cluster-lz ModuleVersion/0.1.1 Name/project Operation/update

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@EspenAlbert EspenAlbert mentioned this pull request Aug 27, 2025
13 tasks
@EspenAlbert EspenAlbert marked this pull request as ready for review August 27, 2025 09:29
@Copilot Copilot AI review requested due to automatic review settings August 27, 2025 09:29
@EspenAlbert EspenAlbert requested a review from a team as a code owner August 27, 2025 09:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds provider_meta support to enable module-level metadata tracking in the MongoDB Atlas Terraform provider. The feature allows terraform configurations to specify module names, versions, and additional User-Agent data that gets included in HTTP requests for analytics purposes.

  • Implements provider_meta schema support for both framework and SDK v2 providers
  • Adds User-Agent enhancement system to capture and transmit module metadata in HTTP headers
  • Creates wrapper resources that inject analytics data into terraform operations

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/provider/provider.go Adds MetaSchema method and wraps resources with analytics functionality
internal/provider/provider_sdk2.go Implements ProviderMetaSchema for SDK v2 and wraps resources
internal/config/user_agent.go Core User-Agent metadata handling and context management
internal/config/user_agent_test.go Comprehensive test coverage for User-Agent functionality
internal/config/transport.go HTTP transport wrapper for User-Agent header modification
internal/config/resource_base.go Framework resource wrapper with analytics integration
internal/config/resource_base_sdkv2.go SDK v2 resource wrapper with analytics integration
internal/config/resource_base_test.go Tests ensuring resource interface preservation
internal/config/transport_test.go Minor formatting cleanup
internal/config/client.go Updates HTTP client transport chain configuration
internal/testutil/unit/provider_mock.go Simplifies mock provider by using embedding

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

github-actions bot commented Sep 2, 2025

This PR has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

@github-actions github-actions bot added the stale label Sep 2, 2025
@EspenAlbert EspenAlbert added the not_stale Not stale issue or PR label Sep 2, 2025
@lantoli lantoli removed the stale label Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not_stale Not stale issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants