-
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
1034904
commit 5815052
Showing
5 changed files
with
170 additions
and
16 deletions.
There are no files selected for viewing
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 = &SearchNodeDS{} | ||
var _ datasource.DataSourceWithConfigure = &SearchNodeDS{} | ||
|
||
func NewSearchNodeDS() datasource.DataSource { | ||
return &SearchNodeDS{ | ||
DSCommon: DSCommon{ | ||
dataSourceName: searchNodeName, | ||
}, | ||
} | ||
} | ||
|
||
type tfSearchNodeDSModel 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 SearchNodeDS struct { | ||
DSCommon | ||
} | ||
|
||
func (d *SearchNodeDS) 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 *SearchNodeDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var searchNodeConfig tfSearchNodeDSModel | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &searchNodeConfig)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
connV2 := d.client.AtlasV2 | ||
projectID := searchNodeConfig.ProjectID.ValueString() | ||
clusterName := searchNodeConfig.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 | ||
} | ||
|
||
newSearchNodeModel, diagnostics := newTFSearchDeployment(ctx, clusterName, deploymentResp, nil) | ||
resp.Diagnostics.Append(diagnostics...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
dsModel := convertToDSModel(newSearchNodeModel) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, dsModel)...) | ||
} | ||
|
||
func convertToDSModel(inputModel *tfSearchNodeRSModel) tfSearchNodeDSModel { | ||
return tfSearchNodeDSModel{ | ||
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 node" | ||
sidebar_current: "docs-mongodbatlas-datasource-search-node" | ||
description: |- | ||
Describes a Search Node. | ||
--- | ||
|
||
# Data Source: mongodbatlas_search_node | ||
|
||
`mongodbatlas_search_node` describes a search node deployment. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "mongodbatlas_search_node" "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. |