Skip to content

Commit 76ef72a

Browse files
authored
chore: Adds provider_meta schema (#3619)
* chore: Adds provider_meta schema * chore: Update user agent header description for clarity
1 parent 3460629 commit 76ef72a

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

internal/provider/provider.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/hashicorp/terraform-plugin-framework/datasource"
1414
"github.com/hashicorp/terraform-plugin-framework/diag"
1515
"github.com/hashicorp/terraform-plugin-framework/provider"
16+
"github.com/hashicorp/terraform-plugin-framework/provider/metaschema"
1617
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
1718
"github.com/hashicorp/terraform-plugin-framework/providerserver"
1819
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -52,11 +53,17 @@ import (
5253
)
5354

5455
const (
55-
MongodbGovCloudURL = "https://cloud.mongodbgov.com"
56-
MongodbGovCloudQAURL = "https://cloud-qa.mongodbgov.com"
57-
MongodbGovCloudDevURL = "https://cloud-dev.mongodbgov.com"
58-
ProviderConfigError = "error in configuring the provider."
59-
MissingAuthAttrError = "either Atlas Programmatic API Keys or AWS Secrets Manager attributes must be set"
56+
MongodbGovCloudURL = "https://cloud.mongodbgov.com"
57+
MongodbGovCloudQAURL = "https://cloud-qa.mongodbgov.com"
58+
MongodbGovCloudDevURL = "https://cloud-dev.mongodbgov.com"
59+
ProviderConfigError = "error in configuring the provider."
60+
MissingAuthAttrError = "either Atlas Programmatic API Keys or AWS Secrets Manager attributes must be set"
61+
ProviderMetaUserAgentExtra = "user_agent_extra"
62+
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}."
63+
ProviderMetaModuleName = "module_name"
64+
ProviderMetaModuleNameDesc = "The name of the module using the provider"
65+
ProviderMetaModuleVersion = "module_version"
66+
ProviderMetaModuleVersionDesc = "The version of the module using the provider"
6067
)
6168

6269
type MongodbtlasProvider struct {
@@ -106,6 +113,26 @@ func (p *MongodbtlasProvider) Metadata(ctx context.Context, req provider.Metadat
106113
resp.Version = version.ProviderVersion
107114
}
108115

116+
func (p *MongodbtlasProvider) MetaSchema(ctx context.Context, req provider.MetaSchemaRequest, resp *provider.MetaSchemaResponse) {
117+
resp.Schema = metaschema.Schema{
118+
Attributes: map[string]metaschema.Attribute{
119+
ProviderMetaModuleName: metaschema.StringAttribute{
120+
Description: ProviderMetaModuleNameDesc,
121+
Optional: true,
122+
},
123+
ProviderMetaModuleVersion: metaschema.StringAttribute{
124+
Description: ProviderMetaModuleVersionDesc,
125+
Optional: true,
126+
},
127+
ProviderMetaUserAgentExtra: metaschema.MapAttribute{
128+
Description: ProviderMetaUserAgentExtraDesc,
129+
Optional: true,
130+
ElementType: types.StringType,
131+
},
132+
},
133+
}
134+
}
135+
109136
func (p *MongodbtlasProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
110137
resp.Schema = schema.Schema{
111138
Blocks: map[string]schema.Block{

internal/provider/provider_sdk2.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ func NewSdkV2Provider() *schema.Provider {
131131
ResourcesMap: getResourcesMap(),
132132
}
133133
provider.ConfigureContextFunc = providerConfigure(provider)
134+
provider.ProviderMetaSchema = map[string]*schema.Schema{
135+
ProviderMetaModuleName: {
136+
Type: schema.TypeString,
137+
Description: ProviderMetaModuleNameDesc,
138+
Optional: true,
139+
},
140+
ProviderMetaModuleVersion: {
141+
Type: schema.TypeString,
142+
Description: ProviderMetaModuleVersionDesc,
143+
Optional: true,
144+
},
145+
ProviderMetaUserAgentExtra: {
146+
Type: schema.TypeMap,
147+
Elem: schema.TypeString,
148+
Description: ProviderMetaUserAgentExtraDesc,
149+
Optional: true,
150+
},
151+
}
134152
return provider
135153
}
136154

0 commit comments

Comments
 (0)