From cd374199dfd06bc31db3ac7bda374199d69d7f08 Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Fri, 1 Sep 2023 11:19:35 +0200 Subject: [PATCH] refactor: extract Configure and Metadata framework functions into single implementation (#1424) * refactor: extract Configure and Metadata framework functions into single implementation * addressing PR comments --- mongodbatlas/fw_common.go | 67 +++++++++++++++++++ ...source_mongodbatlas_alert_configuration.go | 21 ++---- ...ource_mongodbatlas_alert_configurations.go | 21 ++---- ..._data_source_mongodbatlas_database_user.go | 21 ++---- ...data_source_mongodbatlas_database_users.go | 22 ++---- .../fw_data_source_mongodbatlas_project.go | 25 ++----- ...rce_mongodbatlas_project_ip_access_list.go | 23 ++----- .../fw_data_source_mongodbatlas_projects.go | 26 ++----- mongodbatlas/fw_provider.go | 14 ---- ...source_mongodbatlas_alert_configuration.go | 23 ++----- .../fw_resource_mongodbatlas_database_user.go | 35 ++++------ ...esource_mongodbatlas_encryption_at_rest.go | 23 ++----- .../fw_resource_mongodbatlas_project.go | 23 ++----- ...rce_mongodbatlas_project_ip_access_list.go | 24 ++----- 14 files changed, 150 insertions(+), 218 deletions(-) create mode 100644 mongodbatlas/fw_common.go diff --git a/mongodbatlas/fw_common.go b/mongodbatlas/fw_common.go new file mode 100644 index 0000000000..ab609204ec --- /dev/null +++ b/mongodbatlas/fw_common.go @@ -0,0 +1,67 @@ +package mongodbatlas + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/resource" +) + +// RSCommon is used as an embedded struct for all framework resources. Implements the following plugin-framework defined functions: +// - Metadata +// - Configure +// client is left empty and populated by the framework when envoking Configure method. +// resourceName must be defined when creating an instance of a resource. +type RSCommon struct { + client *MongoDBClient + resourceName string +} + +func (r *RSCommon) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, r.resourceName) +} + +func (r *RSCommon) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + client, err := configureClient(req.ProviderData) + if err != nil { + resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) + return + } + r.client = client +} + +// DSCommon is used as an embedded struct for all framework data sources. Implements the following plugin-framework defined functions: +// - Metadata +// - Configure +// client is left empty and populated by the framework when envoking Configure method. +// dataSourceName must be defined when creating an instance of a data source. +type DSCommon struct { + client *MongoDBClient + dataSourceName string +} + +func (d *DSCommon) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, d.dataSourceName) +} + +func (d *DSCommon) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + client, err := configureClient(req.ProviderData) + if err != nil { + resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) + return + } + d.client = client +} + +func configureClient(providerData any) (*MongoDBClient, error) { + if providerData == nil { + return nil, nil + } + + if client, ok := providerData.(*MongoDBClient); ok { + return client, nil + } + + return nil, fmt.Errorf(errorConfigure, providerData) +} diff --git a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration.go b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration.go index dbb48f86cb..24e6a1cd74 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration.go @@ -39,24 +39,15 @@ type tfAlertConfigurationOutputModel struct { } func NewAlertConfigurationDS() datasource.DataSource { - return &AlertConfigurationDS{} + return &AlertConfigurationDS{ + DSCommon: DSCommon{ + dataSourceName: alertConfigurationResourceName, + }, + } } type AlertConfigurationDS struct { - client *MongoDBClient -} - -func (d *AlertConfigurationDS) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, alertConfigurationResourceName) -} - -func (d *AlertConfigurationDS) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - d.client = client + DSCommon } var alertConfigDSSchemaBlocks = map[string]schema.Block{ diff --git a/mongodbatlas/fw_data_source_mongodbatlas_alert_configurations.go b/mongodbatlas/fw_data_source_mongodbatlas_alert_configurations.go index 0286de8316..95975ac187 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_alert_configurations.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_alert_configurations.go @@ -34,24 +34,15 @@ type tfListOptionsModel struct { } func NewAlertConfigurationsDS() datasource.DataSource { - return &AlertConfigurationsDS{} + return &AlertConfigurationsDS{ + DSCommon: DSCommon{ + dataSourceName: alertConfigurationsDataSourceName, + }, + } } type AlertConfigurationsDS struct { - client *MongoDBClient -} - -func (d *AlertConfigurationsDS) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, alertConfigurationsDataSourceName) -} - -func (d *AlertConfigurationsDS) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - d.client = client + DSCommon } func (d *AlertConfigurationsDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { diff --git a/mongodbatlas/fw_data_source_mongodbatlas_database_user.go b/mongodbatlas/fw_data_source_mongodbatlas_database_user.go index 053326ce7c..9def73edb8 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_database_user.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_database_user.go @@ -12,11 +12,15 @@ import ( ) type DatabaseUserDS struct { - client *MongoDBClient + DSCommon } func NewDatabaseUserDS() datasource.DataSource { - return &DatabaseUserDS{} + return &DatabaseUserDS{ + DSCommon: DSCommon{ + dataSourceName: databaseUserResourceName, + }, + } } type tfDatabaseUserDSModel struct { @@ -37,19 +41,6 @@ type tfDatabaseUserDSModel struct { var _ datasource.DataSource = &DatabaseUserDS{} var _ datasource.DataSourceWithConfigure = &DatabaseUserDS{} -func (d *DatabaseUserDS) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, databaseUserResourceName) -} - -func (d *DatabaseUserDS) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - d.client = client -} - func (d *DatabaseUserDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ diff --git a/mongodbatlas/fw_data_source_mongodbatlas_database_users.go b/mongodbatlas/fw_data_source_mongodbatlas_database_users.go index 63667dcabd..49a36f8c02 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_database_users.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_database_users.go @@ -2,7 +2,6 @@ package mongodbatlas import ( "context" - "fmt" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" @@ -17,29 +16,20 @@ const ( ) type DatabaseUsersDS struct { - client *MongoDBClient + DSCommon } func NewDatabaseUsersDS() datasource.DataSource { - return &DatabaseUsersDS{} + return &DatabaseUsersDS{ + DSCommon: DSCommon{ + dataSourceName: databaseUsersDSName, + }, + } } var _ datasource.DataSource = &DatabaseUsersDS{} var _ datasource.DataSourceWithConfigure = &DatabaseUsersDS{} -func (d *DatabaseUsersDS) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, databaseUsersDSName) -} - -func (d *DatabaseUsersDS) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - d.client = client -} - type tfDatabaseUsersDSModel struct { ID types.String `tfsdk:"id"` ProjectID types.String `tfsdk:"project_id"` diff --git a/mongodbatlas/fw_data_source_mongodbatlas_project.go b/mongodbatlas/fw_data_source_mongodbatlas_project.go index d2b4385427..a2440a72ae 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_project.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_project.go @@ -19,11 +19,15 @@ var _ datasource.DataSource = &ProjectDS{} var _ datasource.DataSourceWithConfigure = &ProjectDS{} func NewProjectDS() datasource.DataSource { - return &ProjectDS{} + return &ProjectDS{ + DSCommon: DSCommon{ + dataSourceName: projectResourceName, + }, + } } type ProjectDS struct { - client *MongoDBClient + DSCommon } type tfProjectDSModel struct { @@ -49,23 +53,6 @@ type tfTeamDSModel struct { RoleNames types.List `tfsdk:"role_names"` } -func (d *ProjectDS) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, projectResourceName) -} - -func (d *ProjectDS) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - if req.ProviderData == nil { - return - } - client, ok := req.ProviderData.(*MongoDBClient) - - if !ok { - resp.Diagnostics.AddError(errorConfigureSummary, fmt.Sprintf(errorConfigure, req.ProviderData)) - return - } - d.client = client -} - func (d *ProjectDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ diff --git a/mongodbatlas/fw_data_source_mongodbatlas_project_ip_access_list.go b/mongodbatlas/fw_data_source_mongodbatlas_project_ip_access_list.go index fb595dfca4..da8c30137b 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_project_ip_access_list.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_project_ip_access_list.go @@ -3,7 +3,6 @@ package mongodbatlas import ( "bytes" "context" - "fmt" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -21,30 +20,20 @@ const ( ) type ProjectIPAccessListDS struct { - client *MongoDBClient + DSCommon } func NewProjectIPAccessListDS() datasource.DataSource { - return &ProjectIPAccessListDS{} + return &ProjectIPAccessListDS{ + DSCommon: DSCommon{ + dataSourceName: projectIPAccessList, + }, + } } var _ datasource.DataSource = &ProjectIPAccessListDS{} var _ datasource.DataSourceWithConfigure = &ProjectIPAccessListDS{} -func (d *ProjectIPAccessListDS) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, projectIPAccessList) -} - -func (d *ProjectIPAccessListDS) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - - d.client = client -} - type tfProjectIPAccessListDSModel struct { ID types.String `tfsdk:"id"` ProjectID types.String `tfsdk:"project_id"` diff --git a/mongodbatlas/fw_data_source_mongodbatlas_projects.go b/mongodbatlas/fw_data_source_mongodbatlas_projects.go index a800a29bf7..65d35efdc6 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_projects.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_projects.go @@ -18,11 +18,15 @@ var _ datasource.DataSource = &ProjectsDS{} var _ datasource.DataSourceWithConfigure = &ProjectsDS{} func NewProjectsDS() datasource.DataSource { - return &ProjectsDS{} + return &ProjectsDS{ + DSCommon: DSCommon{ + dataSourceName: projectsDataSourceName, + }, + } } type ProjectsDS struct { - client *MongoDBClient + DSCommon } type tfProjectsDSModel struct { @@ -33,24 +37,6 @@ type tfProjectsDSModel struct { TotalCount types.Int64 `tfsdk:"total_count"` } -func (d *ProjectsDS) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_projects" - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, projectsDataSourceName) -} - -func (d *ProjectsDS) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - if req.ProviderData == nil { - return - } - client, ok := req.ProviderData.(*MongoDBClient) - - if !ok { - resp.Diagnostics.AddError(errorConfigureSummary, fmt.Sprintf(errorConfigure, req.ProviderData)) - return - } - d.client = client -} - func (d *ProjectsDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ diff --git a/mongodbatlas/fw_provider.go b/mongodbatlas/fw_provider.go index c516b87071..ced99b981d 100644 --- a/mongodbatlas/fw_provider.go +++ b/mongodbatlas/fw_provider.go @@ -2,7 +2,6 @@ package mongodbatlas import ( "context" - "fmt" "log" "regexp" "time" @@ -419,16 +418,3 @@ func muxedProviderFactory(sdkV2Provider *sdkv2schema.Provider) func() tfprotov6. } return muxServer.ProviderServer } - -func ConfigureClient(providerData any) (*MongoDBClient, error) { - if providerData == nil { - return nil, nil - } - - client, ok := providerData.(*MongoDBClient) - if !ok { - return nil, fmt.Errorf(errorConfigure, providerData) - } - - return client, nil -} diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go index 8009cc50f5..dc89f824fa 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go @@ -36,15 +36,19 @@ const ( encodedIDKeyProjectID = "project_id" ) -var _ resource.Resource = &AlertConfigurationRS{} +var _ resource.ResourceWithConfigure = &AlertConfigurationRS{} var _ resource.ResourceWithImportState = &AlertConfigurationRS{} func NewAlertConfigurationRS() resource.Resource { - return &AlertConfigurationRS{} + return &AlertConfigurationRS{ + RSCommon: RSCommon{ + resourceName: alertConfigurationResourceName, + }, + } } type AlertConfigurationRS struct { - client *MongoDBClient + RSCommon } type tfAlertConfigurationRSModel struct { @@ -107,19 +111,6 @@ type tfNotificationModel struct { EmailEnabled types.Bool `tfsdk:"email_enabled"` } -func (r *AlertConfigurationRS) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, alertConfigurationResourceName) -} - -func (r *AlertConfigurationRS) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - r.client = client -} - func (r *AlertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ diff --git a/mongodbatlas/fw_resource_mongodbatlas_database_user.go b/mongodbatlas/fw_resource_mongodbatlas_database_user.go index 518e1af501..21482df501 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_database_user.go +++ b/mongodbatlas/fw_resource_mongodbatlas_database_user.go @@ -26,9 +26,21 @@ const ( databaseUserResourceName = "database_user" ) -var _ resource.Resource = &DatabaseUserRS{} +var _ resource.ResourceWithConfigure = &DatabaseUserRS{} var _ resource.ResourceWithImportState = &DatabaseUserRS{} +type DatabaseUserRS struct { + RSCommon +} + +func NewDatabaseUserRS() resource.Resource { + return &DatabaseUserRS{ + RSCommon: RSCommon{ + resourceName: databaseUserResourceName, + }, + } +} + type tfDatabaseUserModel struct { ID types.String `tfsdk:"id"` ProjectID types.String `tfsdk:"project_id"` @@ -60,10 +72,6 @@ type tfScopeModel struct { Type types.String `tfsdk:"type"` } -type DatabaseUserRS struct { - client *MongoDBClient -} - var RoleObjectType = types.ObjectType{AttrTypes: map[string]attr.Type{ "role_name": types.StringType, "collection_name": types.StringType, @@ -198,23 +206,6 @@ func (r *DatabaseUserRS) Schema(ctx context.Context, req resource.SchemaRequest, } } -func NewDatabaseUserRS() resource.Resource { - return &DatabaseUserRS{} -} - -func (r *DatabaseUserRS) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, databaseUserResourceName) -} - -func (r *DatabaseUserRS) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - r.client = client -} - func (r *DatabaseUserRS) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var databaseUserPlan *tfDatabaseUserModel diff --git a/mongodbatlas/fw_resource_mongodbatlas_encryption_at_rest.go b/mongodbatlas/fw_resource_mongodbatlas_encryption_at_rest.go index c35279b88f..713bcad8e3 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_encryption_at_rest.go +++ b/mongodbatlas/fw_resource_mongodbatlas_encryption_at_rest.go @@ -33,15 +33,19 @@ const ( errorUpdateEncryptionAtRest = "error updating Encryption At Rest: %s" ) -var _ resource.Resource = &EncryptionAtRestRS{} +var _ resource.ResourceWithConfigure = &EncryptionAtRestRS{} var _ resource.ResourceWithImportState = &EncryptionAtRestRS{} func NewEncryptionAtRestRS() resource.Resource { - return &EncryptionAtRestRS{} + return &EncryptionAtRestRS{ + RSCommon: RSCommon{ + resourceName: encryptionAtRestResourceName, + }, + } } type EncryptionAtRestRS struct { - client *MongoDBClient + RSCommon } type tfEncryptionAtRestRSModel struct { @@ -77,19 +81,6 @@ type tfGcpKmsConfigModel struct { Enabled types.Bool `tfsdk:"enabled"` } -func (r *EncryptionAtRestRS) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, encryptionAtRestResourceName) -} - -func (r *EncryptionAtRestRS) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - r.client = client -} - func (r *EncryptionAtRestRS) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ diff --git a/mongodbatlas/fw_resource_mongodbatlas_project.go b/mongodbatlas/fw_resource_mongodbatlas_project.go index 0b8fee5ed2..5c82b40777 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_project.go +++ b/mongodbatlas/fw_resource_mongodbatlas_project.go @@ -42,15 +42,19 @@ const ( projectDependentsStateRetry = "RETRY" ) -var _ resource.Resource = &ProjectRS{} +var _ resource.ResourceWithConfigure = &ProjectRS{} var _ resource.ResourceWithImportState = &ProjectRS{} func NewProjectRS() resource.Resource { - return &ProjectRS{} + return &ProjectRS{ + RSCommon: RSCommon{ + resourceName: projectResourceName, + }, + } } type ProjectRS struct { - client *MongoDBClient + RSCommon } type tfProjectRSModel struct { @@ -102,19 +106,6 @@ type AtlastProjectDependents struct { AdvancedClusters *matlas.AdvancedClustersResponse } -func (r *ProjectRS) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, projectResourceName) -} - -func (r *ProjectRS) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - r.client = client -} - func (r *ProjectRS) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ diff --git a/mongodbatlas/fw_resource_mongodbatlas_project_ip_access_list.go b/mongodbatlas/fw_resource_mongodbatlas_project_ip_access_list.go index da747944d0..0b71c9e168 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_project_ip_access_list.go +++ b/mongodbatlas/fw_resource_mongodbatlas_project_ip_access_list.go @@ -43,30 +43,20 @@ type tfProjectIPAccessListModel struct { } type ProjectIPAccessListRS struct { - client *MongoDBClient + RSCommon } func NewProjectIPAccessListRS() resource.Resource { - return &ProjectIPAccessListRS{} + return &ProjectIPAccessListRS{ + RSCommon: RSCommon{ + resourceName: projectIPAccessList, + }, + } } -var _ resource.Resource = &ProjectIPAccessListRS{} +var _ resource.ResourceWithConfigure = &ProjectIPAccessListRS{} var _ resource.ResourceWithImportState = &ProjectIPAccessListRS{} -func (r *ProjectIPAccessListRS) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, projectIPAccessList) -} - -func (r *ProjectIPAccessListRS) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - client, err := ConfigureClient(req.ProviderData) - if err != nil { - resp.Diagnostics.AddError(errorConfigureSummary, err.Error()) - return - } - - r.client = client -} - func (r *ProjectIPAccessListRS) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{