diff --git a/internal/service/searchdeployment/data_source_search_deployment.go b/internal/service/searchdeployment/data_source_search_deployment.go index b193f4526d..4c4e0e0900 100644 --- a/internal/service/searchdeployment/data_source_search_deployment.go +++ b/internal/service/searchdeployment/data_source_search_deployment.go @@ -4,8 +4,6 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -20,52 +18,16 @@ func DataSource() datasource.DataSource { } } -type tfSearchDeploymentDSModel struct { - ID types.String `tfsdk:"id"` - ClusterName types.String `tfsdk:"cluster_name"` - ProjectID types.String `tfsdk:"project_id"` - Specs types.List `tfsdk:"specs"` - StateName types.String `tfsdk:"state_name"` -} - type searchDeploymentDS struct { config.DSCommon } func (d *searchDeploymentDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: map[string]schema.Attribute{ - "id": schema.StringAttribute{ - Computed: true, - }, - "cluster_name": schema.StringAttribute{ - Required: true, - }, - "project_id": schema.StringAttribute{ - Required: true, - }, - "specs": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "instance_size": schema.StringAttribute{ - Computed: true, - }, - "node_count": schema.Int64Attribute{ - Computed: true, - }, - }, - }, - Computed: true, - }, - "state_name": schema.StringAttribute{ - Computed: true, - }, - }, - } + resp.Schema = DataSourceSchema(ctx) } func (d *searchDeploymentDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var searchDeploymentConfig tfSearchDeploymentDSModel + var searchDeploymentConfig TFSearchDeploymentDSModel resp.Diagnostics.Append(req.Config.Get(ctx, &searchDeploymentConfig)...) if resp.Diagnostics.HasError() { return @@ -89,8 +51,8 @@ func (d *searchDeploymentDS) Read(ctx context.Context, req datasource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, dsModel)...) } -func convertToDSModel(inputModel *TFSearchDeploymentRSModel) tfSearchDeploymentDSModel { - return tfSearchDeploymentDSModel{ +func convertToDSModel(inputModel *TFSearchDeploymentRSModel) TFSearchDeploymentDSModel { + return TFSearchDeploymentDSModel{ ID: inputModel.ID, ClusterName: inputModel.ClusterName, ProjectID: inputModel.ProjectID, diff --git a/internal/service/searchdeployment/data_source_search_deployment_schema.go b/internal/service/searchdeployment/data_source_search_deployment_schema.go new file mode 100644 index 0000000000..523e4aa325 --- /dev/null +++ b/internal/service/searchdeployment/data_source_search_deployment_schema.go @@ -0,0 +1,62 @@ +package searchdeployment + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func DataSourceSchema(ctx context.Context) schema.Schema { + return schema.Schema{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "Unique 24-hexadecimal digit string that identifies the search deployment.", + MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the search deployment.", + }, + "cluster_name": schema.StringAttribute{ + Required: true, + Description: "Label that identifies the cluster to return the search nodes for.", + MarkdownDescription: "Label that identifies the cluster to return the search nodes for.", + }, + "project_id": schema.StringAttribute{ + Required: true, + Description: "Unique 24-hexadecimal digit string that identifies your project.", + MarkdownDescription: "Unique 24-hexadecimal digit string that identifies your project.", + }, + "specs": schema.ListNestedAttribute{ + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "instance_size": schema.StringAttribute{ + Computed: true, + Description: "Hardware specification for the search node instance sizes.", + MarkdownDescription: "Hardware specification for the search node instance sizes.", + }, + "node_count": schema.Int64Attribute{ + Computed: true, + Description: "Number of search nodes in the cluster.", + MarkdownDescription: "Number of search nodes in the cluster.", + }, + }, + }, + Description: "List of settings that configure the search nodes for your cluster.", + MarkdownDescription: "List of settings that configure the search nodes for your cluster.", + }, + "state_name": schema.StringAttribute{ + Computed: true, + Description: "Human-readable label that indicates the current operating condition of this search deployment.", + MarkdownDescription: "Human-readable label that indicates the current operating condition of this search deployment.", + }, + }, + } +} + +type TFSearchDeploymentDSModel struct { + ID types.String `tfsdk:"id"` + ClusterName types.String `tfsdk:"cluster_name"` + ProjectID types.String `tfsdk:"project_id"` + Specs types.List `tfsdk:"specs"` + StateName types.String `tfsdk:"state_name"` +} diff --git a/internal/service/searchdeployment/resource_search_deployment.go b/internal/service/searchdeployment/resource_search_deployment.go index 0015a33df8..87dd7d8650 100644 --- a/internal/service/searchdeployment/resource_search_deployment.go +++ b/internal/service/searchdeployment/resource_search_deployment.go @@ -6,16 +6,8 @@ import ( "regexp" "time" - "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" - "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -37,70 +29,8 @@ type searchDeploymentRS struct { config.RSCommon } -type TFSearchDeploymentRSModel struct { - ID types.String `tfsdk:"id"` - ClusterName types.String `tfsdk:"cluster_name"` - ProjectID types.String `tfsdk:"project_id"` - Specs types.List `tfsdk:"specs"` - StateName types.String `tfsdk:"state_name"` - Timeouts timeouts.Value `tfsdk:"timeouts"` -} - -type TFSearchNodeSpecModel struct { - InstanceSize types.String `tfsdk:"instance_size"` - NodeCount types.Int64 `tfsdk:"node_count"` -} - -var SpecObjectType = types.ObjectType{AttrTypes: map[string]attr.Type{ - "instance_size": types.StringType, - "node_count": types.Int64Type, -}} - func (r *searchDeploymentRS) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: map[string]schema.Attribute{ - "id": schema.StringAttribute{ - Computed: true, - }, - "cluster_name": schema.StringAttribute{ - Required: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - "project_id": schema.StringAttribute{ - Required: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - "specs": schema.ListNestedAttribute{ - Validators: []validator.List{ - listvalidator.SizeAtMost(1), - listvalidator.SizeAtLeast(1), - }, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "instance_size": schema.StringAttribute{ - Required: true, - }, - "node_count": schema.Int64Attribute{ - Required: true, - }, - }, - }, - Required: true, - }, - "state_name": schema.StringAttribute{ - Computed: true, - }, - "timeouts": timeouts.Attributes(ctx, timeouts.Opts{ - Create: true, - Update: true, - Delete: true, - }), - }, - } + resp.Schema = ResourceSchema(ctx) } const defaultSearchNodeTimeout time.Duration = 3 * time.Hour diff --git a/internal/service/searchdeployment/resource_search_deployment_schema.go b/internal/service/searchdeployment/resource_search_deployment_schema.go new file mode 100644 index 0000000000..44230ea17b --- /dev/null +++ b/internal/service/searchdeployment/resource_search_deployment_schema.go @@ -0,0 +1,94 @@ +package searchdeployment + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func ResourceSchema(ctx context.Context) schema.Schema { + return schema.Schema{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "Unique 24-hexadecimal digit string that identifies the search deployment.", + MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the search deployment.", + }, + "cluster_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Description: "Label that identifies the cluster to return the search nodes for.", + MarkdownDescription: "Label that identifies the cluster to return the search nodes for.", + }, + "project_id": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Description: "Unique 24-hexadecimal character string that identifies the project.", + MarkdownDescription: "Unique 24-hexadecimal character string that identifies the project.", + }, + "specs": schema.ListNestedAttribute{ + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + listvalidator.SizeAtLeast(1), + }, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "instance_size": schema.StringAttribute{ + Required: true, + Description: "Hardware specification for the search node instance sizes.", + MarkdownDescription: "Hardware specification for the search node instance sizes.", + }, + "node_count": schema.Int64Attribute{ + Required: true, + Description: "Number of search nodes in the cluster.", + MarkdownDescription: "Number of search nodes in the cluster.", + }, + }, + }, + Description: "List of settings that configure the search nodes for your cluster.", + MarkdownDescription: "List of settings that configure the search nodes for your cluster.", + }, + "state_name": schema.StringAttribute{ + Computed: true, + Description: "Human-readable label that indicates the current operating condition of this search deployment.", + MarkdownDescription: "Human-readable label that indicates the current operating condition of this search deployment.", + }, + "timeouts": timeouts.Attributes(ctx, timeouts.Opts{ + Create: true, + Update: true, + Delete: true, + }), + }, + } +} + +type TFSearchDeploymentRSModel struct { + ID types.String `tfsdk:"id"` + ClusterName types.String `tfsdk:"cluster_name"` + ProjectID types.String `tfsdk:"project_id"` + Specs types.List `tfsdk:"specs"` + StateName types.String `tfsdk:"state_name"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +type TFSearchNodeSpecModel struct { + InstanceSize types.String `tfsdk:"instance_size"` + NodeCount types.Int64 `tfsdk:"node_count"` +} + +var SpecObjectType = types.ObjectType{AttrTypes: map[string]attr.Type{ + "instance_size": types.StringType, + "node_count": types.Int64Type, +}} diff --git a/internal/service/searchdeployment/tfplugingen/generator_config.yml b/internal/service/searchdeployment/tfplugingen/generator_config.yml new file mode 100644 index 0000000000..42aab9e1e3 --- /dev/null +++ b/internal/service/searchdeployment/tfplugingen/generator_config.yml @@ -0,0 +1,22 @@ +provider: + name: mongodbatlas + +resources: + search_deployment: + read: + path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/deployment + method: GET + create: + path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/deployment + method: POST + schema: + ignores: [] + + +data_sources: + search_deployment: + read: + path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/deployment + method: GET + schema: + ignores: []