Skip to content

Commit 4806d29

Browse files
authored
feat: Adds encryption_at_rest_provider to mongodbatlas_search_deployment resource and data source (#3152)
* use preview * add encryption_at_rest_provider computed attribute * remove check * dosc * rename files * move adv_cluster config out of resources * fix config * project id * add TODO to version
1 parent 40588f8 commit 4806d29

17 files changed

+134
-118
lines changed

.changelog/3152.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/mongodbatlas_search_deployment: Adds `encryption_at_rest_provider` computed attribute
3+
```
4+
5+
```release-note:enhancement
6+
data-source/mongodbatlas_search_deployment: Adds `encryption_at_rest_provider` computed attribute
7+
```

docs/data-sources/search_deployment.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ output "mongodbatlas_search_deployment_id" {
5858

5959
### Read-Only
6060

61+
- `encryption_at_rest_provider` (String) Cloud service provider that manages your customer keys to provide an additional layer of Encryption At Rest for the cluster.
6162
- `id` (String) Unique 24-hexadecimal digit string that identifies the search deployment.
6263
- `specs` (Attributes List) List of settings that configure the search nodes for your cluster. This list is currently limited to defining a single element. (see [below for nested schema](#nestedatt--specs))
6364
- `state_name` (String) Human-readable label that indicates the current operating condition of this search deployment.

docs/resources/search_deployment.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ output "mongodbatlas_search_deployment_id" {
6868

6969
### Read-Only
7070

71+
- `encryption_at_rest_provider` (String) Cloud service provider that manages your customer keys to provide an additional layer of Encryption At Rest for the cluster.
7172
- `id` (String) Unique 24-hexadecimal digit string that identifies the search deployment.
7273
- `state_name` (String) Human-readable label that indicates the current operating condition of this search deployment.
7374

internal/service/advancedcluster/resource_advanced_cluster_test.go

+2-29
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func testAccAdvancedClusterFlexUpgrade(t *testing.T, instanceSize string, includ
143143
}
144144
if includeDedicated {
145145
steps = append(steps, resource.TestStep{
146-
Config: acc.ConvertAdvancedClusterToPreviewProviderV2(t, true, configBasicDedicated(projectID, clusterName, defaultZoneName)),
146+
Config: acc.ConvertAdvancedClusterToPreviewProviderV2(t, true, acc.ConfigBasicDedicated(projectID, clusterName, defaultZoneName)),
147147
Check: checksBasicDedicated(projectID, clusterName),
148148
})
149149
}
@@ -178,7 +178,7 @@ func TestAccMockableAdvancedCluster_tenantUpgrade(t *testing.T) {
178178
Check: checkTenant(true, projectID, clusterName),
179179
},
180180
{
181-
Config: acc.ConvertAdvancedClusterToPreviewProviderV2(t, true, configBasicDedicated(projectID, clusterName, defaultZoneName)),
181+
Config: acc.ConvertAdvancedClusterToPreviewProviderV2(t, true, acc.ConfigBasicDedicated(projectID, clusterName, defaultZoneName)),
182182
Check: checksBasicDedicated(projectID, clusterName),
183183
},
184184
acc.TestStepImportCluster(resourceName),
@@ -1664,33 +1664,6 @@ func checkTenant(isAcc bool, projectID, name string) resource.TestCheckFunc {
16641664
pluralChecks...)
16651665
}
16661666

1667-
func configBasicDedicated(projectID, name, zoneName string) string {
1668-
zoneNameLine := ""
1669-
if zoneName != "" {
1670-
zoneNameLine = fmt.Sprintf("zone_name = %q", zoneName)
1671-
}
1672-
return fmt.Sprintf(`
1673-
resource "mongodbatlas_advanced_cluster" "test" {
1674-
project_id = %[1]q
1675-
name = %[2]q
1676-
cluster_type = "REPLICASET"
1677-
1678-
replication_specs {
1679-
region_configs {
1680-
priority = 7
1681-
provider_name = "AWS"
1682-
region_name = "US_EAST_1"
1683-
electable_specs {
1684-
node_count = 3
1685-
instance_size = "M10"
1686-
}
1687-
}
1688-
%[3]s
1689-
}
1690-
}
1691-
`, projectID, name, zoneNameLine) + dataSourcesTFNewSchema
1692-
}
1693-
16941667
func checksBasicDedicated(projectID, name string) resource.TestCheckFunc {
16951668
originalChecks := checkTenant(true, projectID, name)
16961669
checkMap := map[string]string{

internal/service/encryptionatrest/resource_migration_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestMigEncryptionAtRest_basicAWS(t *testing.T) {
2828
}
2929
useDatasource = mig.IsProviderVersionAtLeast("1.19.0") // data source introduced in this version
3030
useRequirePrivateNetworking = mig.IsProviderVersionAtLeast("1.28.0") // require_private_networking introduced in this version
31-
useEnabledForSearchNodes = mig.IsProviderVersionAtLeast("1.30.0") // enabled_for_search_nodes introduced in this version
31+
useEnabledForSearchNodes = mig.IsProviderVersionAtLeast("1.30.0") // TODO: confirm version enabled_for_search_nodes introduced in this version
3232
)
3333

3434
resource.Test(t, resource.TestCase{

internal/service/searchdeployment/data_source_search_deployment.go renamed to internal/service/searchdeployment/data_source.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func (d *searchDeploymentDS) Read(ctx context.Context, req datasource.ReadReques
3636
return
3737
}
3838

39-
connV2 := d.Client.AtlasV2
39+
// TODO: update before merging to master: connV2 := d.Client.AtlasV2
40+
connV2 := d.Client.AtlasPreview
4041
projectID := searchDeploymentConfig.ProjectID.ValueString()
4142
clusterName := searchDeploymentConfig.ClusterName.ValueString()
4243
deploymentResp, _, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(ctx, projectID, clusterName).Execute()
@@ -56,10 +57,11 @@ func (d *searchDeploymentDS) Read(ctx context.Context, req datasource.ReadReques
5657

5758
func convertToDSModel(inputModel *TFSearchDeploymentRSModel) TFSearchDeploymentDSModel {
5859
return TFSearchDeploymentDSModel{
59-
ID: inputModel.ID,
60-
ClusterName: inputModel.ClusterName,
61-
ProjectID: inputModel.ProjectID,
62-
Specs: inputModel.Specs,
63-
StateName: inputModel.StateName,
60+
ID: inputModel.ID,
61+
ClusterName: inputModel.ClusterName,
62+
ProjectID: inputModel.ProjectID,
63+
Specs: inputModel.Specs,
64+
StateName: inputModel.StateName,
65+
EncryptionAtRestProvider: inputModel.EncryptionAtRestProvider,
6466
}
6567
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package searchdeployment
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework/types"
5+
)
6+
7+
type TFSearchDeploymentDSModel struct {
8+
ID types.String `tfsdk:"id"`
9+
ClusterName types.String `tfsdk:"cluster_name"`
10+
ProjectID types.String `tfsdk:"project_id"`
11+
Specs types.List `tfsdk:"specs"`
12+
StateName types.String `tfsdk:"state_name"`
13+
EncryptionAtRestProvider types.String `tfsdk:"encryption_at_rest_provider"`
14+
}

internal/service/searchdeployment/data_source_search_deployment_schema.go

-13
This file was deleted.

internal/service/searchdeployment/model_search_deployment.go renamed to internal/service/searchdeployment/model.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
77
"github.com/hashicorp/terraform-plugin-framework/diag"
88
"github.com/hashicorp/terraform-plugin-framework/types"
9-
"go.mongodb.org/atlas-sdk/v20250219001/admin"
9+
10+
// TODO: update before merging to master: "go.mongodb.org/atlas-sdk/v20250219001/admin"
11+
"github.com/mongodb/atlas-sdk-go/admin"
1012
)
1113

1214
func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchDeploymentRSModel) admin.ApiSearchDeploymentRequest {
@@ -27,10 +29,11 @@ func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchD
2729

2830
func NewTFSearchDeployment(ctx context.Context, clusterName string, deployResp *admin.ApiSearchDeploymentResponse, timeout *timeouts.Value, allowMultipleSpecs bool) (*TFSearchDeploymentRSModel, diag.Diagnostics) {
2931
result := TFSearchDeploymentRSModel{
30-
ID: types.StringPointerValue(deployResp.Id),
31-
ClusterName: types.StringValue(clusterName),
32-
ProjectID: types.StringPointerValue(deployResp.GroupId),
33-
StateName: types.StringPointerValue(deployResp.StateName),
32+
ID: types.StringPointerValue(deployResp.Id),
33+
ClusterName: types.StringValue(clusterName),
34+
ProjectID: types.StringPointerValue(deployResp.GroupId),
35+
StateName: types.StringPointerValue(deployResp.StateName),
36+
EncryptionAtRestProvider: types.StringPointerValue(deployResp.EncryptionAtRestProvider),
3437
}
3538

3639
if timeout != nil {

internal/service/searchdeployment/model_search_deployment_test.go renamed to internal/service/searchdeployment/model_test.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"github.com/hashicorp/terraform-plugin-framework/types"
88
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
99
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchdeployment"
10-
"go.mongodb.org/atlas-sdk/v20250219001/admin"
10+
11+
// TODO: update before merging to master: "go.mongodb.org/atlas-sdk/v20250219001/admin"
12+
"github.com/mongodb/atlas-sdk-go/admin"
1113
)
1214

1315
type sdkToTFModelTestCase struct {
@@ -24,6 +26,7 @@ const (
2426
clusterName = "Cluster0"
2527
instanceSize = "S20_HIGHCPU_NVME"
2628
nodeCount = 2
29+
earProvider = "AWS"
2730
)
2831

2932
func TestSearchDeploymentSDKToTFModel(t *testing.T) {
@@ -41,13 +44,15 @@ func TestSearchDeploymentSDKToTFModel(t *testing.T) {
4144
NodeCount: nodeCount,
4245
},
4346
},
47+
EncryptionAtRestProvider: admin.PtrString(earProvider),
4448
},
4549
expectedTFModel: &searchdeployment.TFSearchDeploymentRSModel{
46-
ID: types.StringValue(dummyDeploymentID),
47-
ClusterName: types.StringValue(clusterName),
48-
ProjectID: types.StringValue(dummyProjectID),
49-
StateName: types.StringValue(stateName),
50-
Specs: tfSpecsList(t, instanceSize, nodeCount),
50+
ID: types.StringValue(dummyDeploymentID),
51+
ClusterName: types.StringValue(clusterName),
52+
ProjectID: types.StringValue(dummyProjectID),
53+
StateName: types.StringValue(stateName),
54+
Specs: tfSpecsList(t, instanceSize, nodeCount),
55+
EncryptionAtRestProvider: types.StringValue(earProvider),
5156
},
5257
},
5358
}

internal/service/searchdeployment/resource_search_deployment.go renamed to internal/service/searchdeployment/resource.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ func (r *searchDeploymentRS) Create(ctx context.Context, req resource.CreateRequ
5656
return
5757
}
5858

59-
connV2 := r.Client.AtlasV2
59+
// TODO: update before merging to master: connV2 := d.Client.AtlasV2
60+
connV2 := r.Client.AtlasPreview
6061
projectID := searchDeploymentPlan.ProjectID.ValueString()
6162
clusterName := searchDeploymentPlan.ClusterName.ValueString()
6263
searchDeploymentReq := NewSearchDeploymentReq(ctx, &searchDeploymentPlan)
@@ -91,7 +92,8 @@ func (r *searchDeploymentRS) Read(ctx context.Context, req resource.ReadRequest,
9192
return
9293
}
9394

94-
connV2 := r.Client.AtlasV2
95+
// TODO: update before merging to master: connV2 := d.Client.AtlasV2
96+
connV2 := r.Client.AtlasPreview
9597
projectID := searchDeploymentPlan.ProjectID.ValueString()
9698
clusterName := searchDeploymentPlan.ClusterName.ValueString()
9799
deploymentResp, getResp, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(ctx, projectID, clusterName).Execute()
@@ -119,7 +121,8 @@ func (r *searchDeploymentRS) Update(ctx context.Context, req resource.UpdateRequ
119121
return
120122
}
121123

122-
connV2 := r.Client.AtlasV2
124+
// TODO: update before merging to master: connV2 := d.Client.AtlasV2
125+
connV2 := r.Client.AtlasPreview
123126
projectID := searchDeploymentPlan.ProjectID.ValueString()
124127
clusterName := searchDeploymentPlan.ClusterName.ValueString()
125128
searchDeploymentReq := NewSearchDeploymentReq(ctx, &searchDeploymentPlan)
@@ -154,7 +157,8 @@ func (r *searchDeploymentRS) Delete(ctx context.Context, req resource.DeleteRequ
154157
return
155158
}
156159

157-
connV2 := r.Client.AtlasV2
160+
// TODO: update before merging to master: connV2 := d.Client.AtlasV2
161+
connV2 := r.Client.AtlasPreview
158162
projectID := searchDeploymentState.ProjectID.ValueString()
159163
clusterName := searchDeploymentState.ClusterName.ValueString()
160164
if _, _, err := connV2.AtlasSearchApi.DeleteAtlasSearchDeployment(ctx, projectID, clusterName).Execute(); err != nil {

internal/service/searchdeployment/resource_search_deployment_migration_test.go renamed to internal/service/searchdeployment/resource_migration_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import (
1212
func TestMigSearchDeployment_basic(t *testing.T) {
1313
var (
1414
resourceName = "mongodbatlas_search_deployment.test"
15-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
16-
projectName = acc.RandomProjectName()
15+
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_EAR_PE_AWS_ID") // to use RequirePrivateNetworking, Atlas Project is required to have FF enabled
1716
clusterName = acc.RandomClusterName()
1817
instanceSize = "S30_HIGHCPU_NVME"
1918
searchNodeCount = 3
20-
config = configBasic(orgID, projectName, clusterName, instanceSize, searchNodeCount)
19+
config = configBasic(projectID, clusterName, instanceSize, searchNodeCount)
2120
)
22-
mig.SkipIfVersionBelow(t, "1.13.0")
21+
mig.SkipIfVersionBelow(t, "1.30.0") // TODO: confirm version enabled_for_search_nodes introduced in this version
2322
resource.ParallelTest(t, resource.TestCase{
2423
PreCheck: func() { mig.PreCheckBasic(t) },
2524
CheckDestroy: checkDestroy,

internal/service/searchdeployment/resource_search_deployment_schema.go renamed to internal/service/searchdeployment/resource_schema.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,22 @@ func ResourceSchema(ctx context.Context) schema.Schema {
6363
Update: true,
6464
Delete: true,
6565
}),
66+
"encryption_at_rest_provider": schema.StringAttribute{
67+
Computed: true,
68+
MarkdownDescription: "Cloud service provider that manages your customer keys to provide an additional layer of Encryption At Rest for the cluster.",
69+
},
6670
},
6771
}
6872
}
6973

7074
type TFSearchDeploymentRSModel struct {
71-
ID types.String `tfsdk:"id"`
72-
ClusterName types.String `tfsdk:"cluster_name"`
73-
ProjectID types.String `tfsdk:"project_id"`
74-
Specs types.List `tfsdk:"specs"`
75-
StateName types.String `tfsdk:"state_name"`
76-
Timeouts timeouts.Value `tfsdk:"timeouts"`
75+
ID types.String `tfsdk:"id"`
76+
ClusterName types.String `tfsdk:"cluster_name"`
77+
ProjectID types.String `tfsdk:"project_id"`
78+
Specs types.List `tfsdk:"specs"`
79+
StateName types.String `tfsdk:"state_name"`
80+
Timeouts timeouts.Value `tfsdk:"timeouts"`
81+
EncryptionAtRestProvider types.String `tfsdk:"encryption_at_rest_provider"`
7782
}
7883

7984
type TFSearchNodeSpecModel struct {

0 commit comments

Comments
 (0)