diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 4873ddcbf1..d55969648c 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/provider/metaschema" "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -52,11 +53,17 @@ import ( ) const ( - MongodbGovCloudURL = "https://cloud.mongodbgov.com" - MongodbGovCloudQAURL = "https://cloud-qa.mongodbgov.com" - MongodbGovCloudDevURL = "https://cloud-dev.mongodbgov.com" - ProviderConfigError = "error in configuring the provider." - MissingAuthAttrError = "either Atlas Programmatic API Keys or AWS Secrets Manager attributes must be set" + MongodbGovCloudURL = "https://cloud.mongodbgov.com" + MongodbGovCloudQAURL = "https://cloud-qa.mongodbgov.com" + MongodbGovCloudDevURL = "https://cloud-dev.mongodbgov.com" + ProviderConfigError = "error in configuring the provider." + MissingAuthAttrError = "either Atlas Programmatic API Keys or AWS Secrets Manager attributes must be set" + ProviderMetaUserAgentExtra = "user_agent_extra" + ProviderMetaUserAgentExtraDesc = "You can extend the user agent header for each request made by the provider to the Atlas Admin API. The Key Values will be formatted as {key}/{value}." + ProviderMetaModuleName = "module_name" + ProviderMetaModuleNameDesc = "The name of the module using the provider" + ProviderMetaModuleVersion = "module_version" + ProviderMetaModuleVersionDesc = "The version of the module using the provider" ) type MongodbtlasProvider struct { @@ -106,6 +113,26 @@ func (p *MongodbtlasProvider) Metadata(ctx context.Context, req provider.Metadat resp.Version = version.ProviderVersion } +func (p *MongodbtlasProvider) MetaSchema(ctx context.Context, req provider.MetaSchemaRequest, resp *provider.MetaSchemaResponse) { + resp.Schema = metaschema.Schema{ + Attributes: map[string]metaschema.Attribute{ + ProviderMetaModuleName: metaschema.StringAttribute{ + Description: ProviderMetaModuleNameDesc, + Optional: true, + }, + ProviderMetaModuleVersion: metaschema.StringAttribute{ + Description: ProviderMetaModuleVersionDesc, + Optional: true, + }, + ProviderMetaUserAgentExtra: metaschema.MapAttribute{ + Description: ProviderMetaUserAgentExtraDesc, + Optional: true, + ElementType: types.StringType, + }, + }, + } +} + func (p *MongodbtlasProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { resp.Schema = schema.Schema{ Blocks: map[string]schema.Block{ diff --git a/internal/provider/provider_sdk2.go b/internal/provider/provider_sdk2.go index 052a3518d7..5d31fe9492 100644 --- a/internal/provider/provider_sdk2.go +++ b/internal/provider/provider_sdk2.go @@ -131,6 +131,24 @@ func NewSdkV2Provider() *schema.Provider { ResourcesMap: getResourcesMap(), } provider.ConfigureContextFunc = providerConfigure(provider) + provider.ProviderMetaSchema = map[string]*schema.Schema{ + ProviderMetaModuleName: { + Type: schema.TypeString, + Description: ProviderMetaModuleNameDesc, + Optional: true, + }, + ProviderMetaModuleVersion: { + Type: schema.TypeString, + Description: ProviderMetaModuleVersionDesc, + Optional: true, + }, + ProviderMetaUserAgentExtra: { + Type: schema.TypeMap, + Elem: schema.TypeString, + Description: ProviderMetaUserAgentExtraDesc, + Optional: true, + }, + } return provider }