-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement search node data source with acceptance tests and docs
- Loading branch information
1 parent
7a5d987
commit 6fc6e3e
Showing
5 changed files
with
195 additions
and
40 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
mongodbatlas/fw_data_source_mongodbatlas_search_deployment.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ datasource.DataSource = &SearchDeploymentDS{} | ||
var _ datasource.DataSourceWithConfigure = &SearchDeploymentDS{} | ||
|
||
func NewSearchDeploymentDS() datasource.DataSource { | ||
return &SearchDeploymentDS{ | ||
DSCommon: DSCommon{ | ||
dataSourceName: searchDeploymentName, | ||
}, | ||
} | ||
} | ||
|
||
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 { | ||
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, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *SearchDeploymentDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var searchDeploymentConfig tfSearchDeploymentDSModel | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &searchDeploymentConfig)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
connV2 := d.client.AtlasV2 | ||
projectID := searchDeploymentConfig.ProjectID.ValueString() | ||
clusterName := searchDeploymentConfig.ClusterName.ValueString() | ||
deploymentResp, _, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(ctx, projectID, clusterName).Execute() | ||
if err != nil { | ||
resp.Diagnostics.AddError("error getting search node information", err.Error()) | ||
return | ||
} | ||
|
||
newSearchDeploymentModel, diagnostics := newTFSearchDeployment(ctx, clusterName, deploymentResp, nil) | ||
resp.Diagnostics.Append(diagnostics...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
dsModel := convertToDSModel(newSearchDeploymentModel) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, dsModel)...) | ||
} | ||
|
||
func convertToDSModel(inputModel *tfSearchDeploymentRSModel) tfSearchDeploymentDSModel { | ||
return tfSearchDeploymentDSModel{ | ||
ID: inputModel.ID, | ||
ClusterName: inputModel.ClusterName, | ||
ProjectID: inputModel.ProjectID, | ||
Specs: inputModel.Specs, | ||
StateName: inputModel.StateName, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
layout: "mongodbatlas" | ||
page_title: "MongoDB Atlas: search deployment" | ||
sidebar_current: "docs-mongodbatlas-datasource-search-deployment" | ||
description: |- | ||
Describes a Search Deployment. | ||
--- | ||
|
||
# Data Source: mongodbatlas_search_deployment | ||
|
||
`mongodbatlas_search_deployment` describes a search node deployment. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "mongodbatlas_search_deployment" "test" { | ||
project_id = "<PROJECT_ID>" | ||
cluster_name = "<CLUSTER_NAME>" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `project_id` - (Required) The unique identifier for the [project](https://docs.atlas.mongodb.com/organizations-projects/#std-label-projects) that contains the specified cluster. | ||
* `cluster_name` - (Required) The name of the cluster containing a search node deployment. | ||
|
||
## Attributes Reference | ||
|
||
* `specs` - List of settings that configure the search nodes for your cluster. See [specs](#specs). | ||
* `state_name` - Human-readable label that indicates the current operating condition of this search node deployment. | ||
|
||
### Specs | ||
TODO: add proper link here | ||
* `instance_size` - (Required) Hardware specification for the search node instance sizes. The [MongoDB Atlas API](https://docs.atlas.mongodb.com/reference/api/) describes the valid values. More details can also be found in the [Search Node Documentation](https://www.mongodb.com/docs/atlas/cluster-config/multi-cloud-distribution/#search-tier). | ||
* `node_count` - (Required) Number of search nodes in the cluster. | ||
|
||
|
||
TODO: add proper link here | ||
For more information see: [MongoDB Atlas API - Search Node](https://docs.atlas.mongodb.com/reference/api/) Documentation. |