Skip to content

Commit 16bcebd

Browse files
feat: search node management with mongodbatlas_search_deployment resource and data source (#1633)
* TEMPORARY - use SDK Preview * feat: new search node resource * wip - acceptance tests * fixes in tests and adding CI workflow * use state property to verify transition for create, update, and delete operations * add specific documentation to clarify specs as a list nested attribute * addressing PR comments * addressing doc reviews * adjusting to new state names and transitions * refactor name from search_node to search_deployment * feat: implement search node data source with acceptance tests and docs * Revert "TEMPORARY - use SDK Preview" This reverts commit c556c7d. * adjust documentation links * small naming change * change in search deployment example readme phrasing Co-authored-by: Marco Suma <[email protected]> --------- Co-authored-by: Marco Suma <[email protected]>
1 parent 7cbd38e commit 16bcebd

13 files changed

+819
-0
lines changed

.github/workflows/acceptance-tests.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
cluster_outage_simulation: ${{ steps.filter.outputs.cluster_outage_simulation }}
2323
advanced_cluster: ${{ steps.filter.outputs.advanced_cluster }}
2424
cluster: ${{ steps.filter.outputs.cluster }}
25+
search_deployment: ${{ steps.filter.outputs.search_deployment }}
2526
generic: ${{ steps.filter.outputs.generic }}
2627
backup_online_archive: ${{ steps.filter.outputs.backup_online_archive }}
2728
backup_snapshots: ${{ steps.filter.outputs.backup_snapshots }}
@@ -49,6 +50,8 @@ jobs:
4950
- 'mongodbatlas/**advanced_cluster**.go'
5051
cluster:
5152
- 'mongodbatlas/**mongodbatlas_cluster**.go'
53+
search_deployment:
54+
- 'mongodbatlas/**search_deployment**.go'
5255
generic:
5356
- 'mongodbatlas/data_source_mongodbatlas_backup_compliance_policy*.go'
5457
- 'mongodbatlas/resource_mongodbatlas_backup_compliance_policy*.go'
@@ -185,6 +188,30 @@ jobs:
185188
TEST_REGEX: "^TestAccClusterRSCluster"
186189
run: make testacc
187190

191+
search_deployment:
192+
needs: [ change-detection ]
193+
if: ${{ needs.change-detection.outputs.search_deployment == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'run-testacc' || github.event.label.name == 'run-testacc-search-deployment' || inputs.parent-event-name == 'release' }}
194+
runs-on: ubuntu-latest
195+
steps:
196+
- name: Checkout
197+
uses: actions/checkout@v4
198+
- name: Set up Go
199+
uses: actions/setup-go@v4
200+
with:
201+
go-version-file: 'go.mod'
202+
- name: Acceptance Tests
203+
env:
204+
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
205+
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
206+
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
207+
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
208+
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
209+
TF_LOG: ${{ vars.LOG_LEVEL }}
210+
TF_ACC: 1
211+
PARALLEL_GO_TEST: 20
212+
TEST_REGEX: "^TestAccSearchDeployment"
213+
run: make testacc
214+
188215
generic: # Acceptance tests that do not use any time-consuming resource (example: cluster)
189216
needs: [ change-detection ]
190217
if: ${{ needs.change-detection.outputs.generic == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'run-testacc' || github.event.label.name == 'run-testacc-generic' || inputs.parent-event-name == 'release' }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# MongoDB Atlas Provider - Atlas Cluster with dedicated Search Nodes Deployment
2+
3+
This example shows how you can use Atlas Dedicated Search Nodes in Terraform. As part of it, a project and cluster resource are created as a prerequisite.
4+
5+
Variables Required to be set:
6+
7+
- `public_key`: Atlas public key
8+
- `private_key`: Atlas private key
9+
- `org_id`: Organization ID where the project and cluster will be created.
10+
11+
For additional information you can visit the [Search Node Documentation](https://www.mongodb.com/docs/atlas/cluster-config/multi-cloud-distribution/#search-nodes-for-workload-isolation).
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
resource "mongodbatlas_project" "example" {
2+
name = "project-name"
3+
org_id = var.org_id
4+
}
5+
6+
resource "mongodbatlas_advanced_cluster" "example" {
7+
project_id = mongodbatlas_project.example.id
8+
name = "ClusterExample"
9+
cluster_type = "REPLICASET"
10+
11+
replication_specs {
12+
region_configs {
13+
electable_specs {
14+
instance_size = "M10"
15+
node_count = 3
16+
}
17+
provider_name = "AWS"
18+
priority = 7
19+
region_name = "US_EAST_1"
20+
}
21+
}
22+
}
23+
24+
resource "mongodbatlas_search_deployment" "example" {
25+
project_id = mongodbatlas_project.example.id
26+
cluster_name = mongodbatlas_advanced_cluster.example.name
27+
specs = [
28+
{
29+
instance_size = "S20_HIGHCPU_NVME"
30+
node_count = 2
31+
}
32+
]
33+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
variable "public_key" {
2+
description = "Public API key to authenticate to Atlas"
3+
type = string
4+
}
5+
variable "private_key" {
6+
description = "Private API key to authenticate to Atlas"
7+
type = string
8+
}
9+
variable "org_id" {
10+
description = "Atlas Organization ID"
11+
type = string
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_providers {
3+
mongodbatlas = {
4+
source = "mongodb/mongodbatlas"
5+
version = "~> 1.13"
6+
}
7+
}
8+
required_version = ">= 1.0"
9+
}

mongodbatlas/framework/retry/retry_state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ const (
44
RetryStrategyPendingState = "PENDING"
55
RetryStrategyCompletedState = "COMPLETED"
66
RetryStrategyErrorState = "ERROR"
7+
RetryStrategyPausedState = "PAUSED"
8+
RetryStrategyUpdatingState = "UPDATING"
9+
RetryStrategyIdleState = "IDLE"
10+
RetryStrategyDeletedState = "DELETED"
711
)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package mongodbatlas
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/datasource"
7+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
8+
"github.com/hashicorp/terraform-plugin-framework/types"
9+
)
10+
11+
var _ datasource.DataSource = &SearchDeploymentDS{}
12+
var _ datasource.DataSourceWithConfigure = &SearchDeploymentDS{}
13+
14+
func NewSearchDeploymentDS() datasource.DataSource {
15+
return &SearchDeploymentDS{
16+
DSCommon: DSCommon{
17+
dataSourceName: searchDeploymentName,
18+
},
19+
}
20+
}
21+
22+
type tfSearchDeploymentDSModel struct {
23+
ID types.String `tfsdk:"id"`
24+
ClusterName types.String `tfsdk:"cluster_name"`
25+
ProjectID types.String `tfsdk:"project_id"`
26+
Specs types.List `tfsdk:"specs"`
27+
StateName types.String `tfsdk:"state_name"`
28+
}
29+
30+
type SearchDeploymentDS struct {
31+
DSCommon
32+
}
33+
34+
func (d *SearchDeploymentDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
35+
resp.Schema = schema.Schema{
36+
Attributes: map[string]schema.Attribute{
37+
"id": schema.StringAttribute{
38+
Computed: true,
39+
},
40+
"cluster_name": schema.StringAttribute{
41+
Required: true,
42+
},
43+
"project_id": schema.StringAttribute{
44+
Required: true,
45+
},
46+
"specs": schema.ListNestedAttribute{
47+
NestedObject: schema.NestedAttributeObject{
48+
Attributes: map[string]schema.Attribute{
49+
"instance_size": schema.StringAttribute{
50+
Computed: true,
51+
},
52+
"node_count": schema.Int64Attribute{
53+
Computed: true,
54+
},
55+
},
56+
},
57+
Computed: true,
58+
},
59+
"state_name": schema.StringAttribute{
60+
Computed: true,
61+
},
62+
},
63+
}
64+
}
65+
66+
func (d *SearchDeploymentDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
67+
var searchDeploymentConfig tfSearchDeploymentDSModel
68+
resp.Diagnostics.Append(req.Config.Get(ctx, &searchDeploymentConfig)...)
69+
if resp.Diagnostics.HasError() {
70+
return
71+
}
72+
73+
connV2 := d.client.AtlasV2
74+
projectID := searchDeploymentConfig.ProjectID.ValueString()
75+
clusterName := searchDeploymentConfig.ClusterName.ValueString()
76+
deploymentResp, _, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(ctx, projectID, clusterName).Execute()
77+
if err != nil {
78+
resp.Diagnostics.AddError("error getting search node information", err.Error())
79+
return
80+
}
81+
82+
newSearchDeploymentModel, diagnostics := newTFSearchDeployment(ctx, clusterName, deploymentResp, nil)
83+
resp.Diagnostics.Append(diagnostics...)
84+
if resp.Diagnostics.HasError() {
85+
return
86+
}
87+
dsModel := convertToDSModel(newSearchDeploymentModel)
88+
resp.Diagnostics.Append(resp.State.Set(ctx, dsModel)...)
89+
}
90+
91+
func convertToDSModel(inputModel *tfSearchDeploymentRSModel) tfSearchDeploymentDSModel {
92+
return tfSearchDeploymentDSModel{
93+
ID: inputModel.ID,
94+
ClusterName: inputModel.ClusterName,
95+
ProjectID: inputModel.ProjectID,
96+
Specs: inputModel.Specs,
97+
StateName: inputModel.StateName,
98+
}
99+
}

mongodbatlas/fw_provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ func (p *MongodbtlasProvider) DataSources(context.Context) []func() datasource.D
413413
NewProjectIPAccessListDS,
414414
NewAtlasUserDS,
415415
NewAtlasUsersDS,
416+
NewSearchDeploymentDS,
416417
}
417418
}
418419

@@ -423,6 +424,7 @@ func (p *MongodbtlasProvider) Resources(context.Context) []func() resource.Resou
423424
NewDatabaseUserRS,
424425
NewAlertConfigurationRS,
425426
NewProjectIPAccessListRS,
427+
NewSearchDeploymentRS,
426428
}
427429
}
428430

0 commit comments

Comments
 (0)