Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 32 additions & 5 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = "Key Values of that will be formatted as {key}/{value} in the User-Agent Header"
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 {
Expand Down Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

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

don't we want to have this required if provider_meta is used? similar for version

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so.
Not guaranteed the provider_meta will always be used inside modules in the future

},
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{
Expand Down
18 changes: 18 additions & 0 deletions internal/provider/provider_sdk2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down