@@ -11,34 +11,68 @@ import (
11
11
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
12
12
)
13
13
14
+ const (
15
+ resourceID = "mongodbatlas_search_deployment.test"
16
+ dataSourceID = "data.mongodbatlas_search_deployment.test"
17
+ )
18
+
14
19
func TestAccSearchDeployment_basic (t * testing.T ) {
15
20
var (
16
- resourceName = "mongodbatlas_search_deployment.test"
17
- orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
18
- projectName = acc .RandomProjectName ()
19
- clusterName = acc .RandomClusterName ()
21
+ orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
22
+ projectName = acc .RandomProjectName ()
23
+ clusterName = acc .RandomClusterName ()
20
24
)
21
25
resource .ParallelTest (t , resource.TestCase {
22
26
PreCheck : func () { acc .PreCheckBasic (t ) },
23
27
ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
24
28
CheckDestroy : checkDestroy ,
25
29
Steps : []resource.TestStep {
26
- newSearchNodeTestStep (resourceName , orgID , projectName , clusterName , "S20_HIGHCPU_NVME" , 3 ),
27
- newSearchNodeTestStep (resourceName , orgID , projectName , clusterName , "S30_HIGHCPU_NVME" , 4 ),
30
+ newSearchNodeTestStep (resourceID , orgID , projectName , clusterName , "S20_HIGHCPU_NVME" , 3 ),
31
+ newSearchNodeTestStep (resourceID , orgID , projectName , clusterName , "S30_HIGHCPU_NVME" , 4 ),
28
32
{
29
33
Config : configBasic (orgID , projectName , clusterName , "S30_HIGHCPU_NVME" , 4 ),
30
- ResourceName : resourceName ,
31
- ImportStateIdFunc : importStateIDFunc (resourceName ),
34
+ ResourceName : resourceID ,
35
+ ImportStateIdFunc : importStateIDFunc (resourceID ),
32
36
ImportState : true ,
33
37
ImportStateVerify : true ,
34
38
},
35
39
},
36
40
})
37
41
}
38
42
43
+ func TestAccSearchDeployment_multiRegion (t * testing.T ) {
44
+ var (
45
+ clusterInfo = acc .GetClusterInfo (t , & acc.ClusterRequest {
46
+ ClusterName : "multi-region-cluster" ,
47
+ ReplicationSpecs : []acc.ReplicationSpecRequest {
48
+ {
49
+ Region : "US_EAST_1" ,
50
+ ExtraRegionConfigs : []acc.ReplicationSpecRequest {
51
+ {Region : "US_WEST_2" , Priority : 6 , InstanceSize : "M10" , NodeCount : 2 },
52
+ },
53
+ },
54
+ },
55
+ })
56
+ )
57
+ resource .ParallelTest (t , resource.TestCase {
58
+ PreCheck : func () { acc .PreCheckBasic (t ) },
59
+ ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
60
+ CheckDestroy : checkDestroy ,
61
+ Steps : []resource.TestStep {
62
+ {
63
+ Config : clusterInfo .TerraformStr + configSearchDeployment (clusterInfo .ProjectID , clusterInfo .TerraformNameRef , "S20_HIGHCPU_NVME" , 2 ),
64
+ Check : resource .ComposeAggregateTestCheckFunc (
65
+ checkExists (resourceID ),
66
+ resource .TestCheckResourceAttr (resourceID , "specs.#" , "1" ),
67
+ ),
68
+ },
69
+ },
70
+ })
71
+ }
72
+
39
73
func newSearchNodeTestStep (resourceName , orgID , projectName , clusterName , instanceSize string , searchNodeCount int ) resource.TestStep {
40
74
resourceChecks := searchNodeChecks (resourceName , clusterName , instanceSize , searchNodeCount )
41
- dataSourceChecks := searchNodeChecks (fmt . Sprintf ( "data.%s" , resourceName ) , clusterName , instanceSize , searchNodeCount )
75
+ dataSourceChecks := searchNodeChecks (dataSourceID , clusterName , instanceSize , searchNodeCount )
42
76
return resource.TestStep {
43
77
Config : configBasic (orgID , projectName , clusterName , instanceSize , searchNodeCount ),
44
78
Check : resource .ComposeAggregateTestCheckFunc (append (resourceChecks , dataSourceChecks ... )... ),
@@ -80,6 +114,21 @@ func configBasic(orgID, projectName, clusterName, instanceSize string, searchNod
80
114
` , clusterConfig , instanceSize , searchNodeCount )
81
115
}
82
116
117
+ func configSearchDeployment (projectID , clusterNameRef , instanceSize string , searchNodeCount int ) string {
118
+ return fmt .Sprintf (`
119
+ resource "mongodbatlas_search_deployment" "test" {
120
+ project_id = %[1]q
121
+ cluster_name = %[2]s
122
+ specs = [
123
+ {
124
+ instance_size = %[3]q
125
+ node_count = %[4]d
126
+ }
127
+ ]
128
+ }
129
+ ` , projectID , clusterNameRef , instanceSize , searchNodeCount )
130
+ }
131
+
83
132
func advancedClusterConfig (orgID , projectName , clusterName string ) string {
84
133
return fmt .Sprintf (`
85
134
resource "mongodbatlas_project" "test" {
0 commit comments