Skip to content

Commit 958c6de

Browse files
authored
feat: Adds support for Sample stream type to mongodbatlas_stream_connection (#2026)
1 parent 917da62 commit 958c6de

File tree

7 files changed

+152
-21
lines changed

7 files changed

+152
-21
lines changed

examples/mongodbatlas_stream_connection/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ resource "mongodbatlas_stream_connection" "example-kafka-ssl" {
5858
}
5959
}
6060

61+
resource "mongodbatlas_stream_connection" "example-sample" {
62+
project_id = var.project_id
63+
instance_name = mongodbatlas_stream_instance.example.instance_name
64+
connection_name = "sample_stream_solar"
65+
type = "Sample"
66+
}
67+
6168
data "mongodbatlas_stream_connection" "example-kafka-ssl" {
6269
project_id = var.project_id
6370
instance_name = mongodbatlas_stream_instance.example.instance_name

internal/service/streamconnection/data_source_stream_connection_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ func TestAccStreamDSStreamConnection_cluster(t *testing.T) {
6868
})
6969
}
7070

71+
func TestAccStreamDSStreamConnection_sample(t *testing.T) {
72+
var (
73+
dataSourceName = "data.mongodbatlas_stream_connection.test"
74+
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
75+
projectName = acc.RandomProjectName()
76+
instanceName = acc.RandomName()
77+
sampleName = "sample_stream_solar"
78+
)
79+
resource.ParallelTest(t, resource.TestCase{
80+
PreCheck: func() { acc.PreCheckPreviewFlag(t); acc.PreCheckBasic(t) },
81+
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
82+
CheckDestroy: CheckDestroyStreamConnection,
83+
Steps: []resource.TestStep{
84+
{
85+
Config: streamConnectionDataSourceConfig(sampleStreamConnectionConfig(orgID, projectName, instanceName, sampleName)),
86+
Check: sampleStreamConnectionAttributeChecks(dataSourceName, instanceName, sampleName),
87+
},
88+
},
89+
})
90+
}
91+
7192
func streamConnectionDataSourceConfig(streamConnectionConfig string) string {
7293
return fmt.Sprintf(`
7394
%s

internal/service/streamconnection/model_stream_connection_test.go

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ import (
1212
)
1313

1414
const (
15-
connectionName = "Connection"
16-
typeValue = ""
17-
clusterName = "Cluster0"
18-
dummyProjectID = "111111111111111111111111"
19-
instanceName = "InstanceName"
20-
authMechanism = "PLAIN"
21-
authUsername = "user1"
22-
securityProtocol = "SSL"
23-
bootstrapServers = "localhost:9092,another.host:9092"
24-
dbRole = "customRole"
25-
dbRoleType = "CUSTOM"
15+
connectionName = "Connection"
16+
typeValue = ""
17+
clusterName = "Cluster0"
18+
dummyProjectID = "111111111111111111111111"
19+
instanceName = "InstanceName"
20+
authMechanism = "PLAIN"
21+
authUsername = "user1"
22+
securityProtocol = "SSL"
23+
bootstrapServers = "localhost:9092,another.host:9092"
24+
dbRole = "customRole"
25+
dbRoleType = "CUSTOM"
26+
sampleConnectionName = "sample_stream_solar"
2627
)
2728

2829
var configMap = map[string]string{
@@ -150,6 +151,25 @@ func TestStreamConnectionSDKToTFModel(t *testing.T) {
150151
DBRoleToExecute: types.ObjectNull(streamconnection.DBRoleToExecuteObjectType.AttrTypes),
151152
},
152153
},
154+
{
155+
name: "Sample connection type sample_stream_solar sample",
156+
SDKResp: &admin.StreamsConnection{
157+
Name: admin.PtrString(sampleConnectionName),
158+
Type: admin.PtrString("Sample"),
159+
},
160+
providedProjID: dummyProjectID,
161+
providedInstanceName: instanceName,
162+
expectedTFModel: &streamconnection.TFStreamConnectionModel{
163+
ProjectID: types.StringValue(dummyProjectID),
164+
InstanceName: types.StringValue(instanceName),
165+
ConnectionName: types.StringValue(sampleConnectionName),
166+
Type: types.StringValue("Sample"),
167+
Authentication: types.ObjectNull(streamconnection.ConnectionAuthenticationObjectType.AttrTypes),
168+
Config: types.MapNull(types.StringType),
169+
Security: types.ObjectNull(streamconnection.ConnectionSecurityObjectType.AttrTypes),
170+
DBRoleToExecute: types.ObjectNull(streamconnection.DBRoleToExecuteObjectType.AttrTypes),
171+
},
172+
},
153173
}
154174

155175
for _, tc := range testCases {
@@ -202,21 +222,25 @@ func TestStreamConnectionsSDKToTFModel(t *testing.T) {
202222
Type: admin.PtrString(dbRoleType),
203223
},
204224
},
225+
{
226+
Name: admin.PtrString(sampleConnectionName),
227+
Type: admin.PtrString("Sample"),
228+
},
205229
},
206-
TotalCount: admin.PtrInt(2),
230+
TotalCount: admin.PtrInt(3),
207231
},
208232
providedConfig: &streamconnection.TFStreamConnectionsDSModel{
209233
ProjectID: types.StringValue(dummyProjectID),
210234
InstanceName: types.StringValue(instanceName),
211235
PageNum: types.Int64Value(1),
212-
ItemsPerPage: types.Int64Value(2),
236+
ItemsPerPage: types.Int64Value(3),
213237
},
214238
expectedTFModel: &streamconnection.TFStreamConnectionsDSModel{
215239
ProjectID: types.StringValue(dummyProjectID),
216240
InstanceName: types.StringValue(instanceName),
217241
PageNum: types.Int64Value(1),
218-
ItemsPerPage: types.Int64Value(2),
219-
TotalCount: types.Int64Value(2),
242+
ItemsPerPage: types.Int64Value(3),
243+
TotalCount: types.Int64Value(3),
220244
Results: []streamconnection.TFStreamConnectionModel{
221245
{
222246
ID: types.StringValue(fmt.Sprintf("%s-%s-%s", instanceName, dummyProjectID, connectionName)),
@@ -242,6 +266,18 @@ func TestStreamConnectionsSDKToTFModel(t *testing.T) {
242266
Security: types.ObjectNull(streamconnection.ConnectionSecurityObjectType.AttrTypes),
243267
DBRoleToExecute: tfDBRoleToExecuteObject(t, dbRole, dbRoleType),
244268
},
269+
{
270+
ID: types.StringValue(fmt.Sprintf("%s-%s-%s", instanceName, dummyProjectID, sampleConnectionName)),
271+
ProjectID: types.StringValue(dummyProjectID),
272+
InstanceName: types.StringValue(instanceName),
273+
ConnectionName: types.StringValue(sampleConnectionName),
274+
Type: types.StringValue("Sample"),
275+
ClusterName: types.StringNull(),
276+
Authentication: types.ObjectNull(streamconnection.ConnectionAuthenticationObjectType.AttrTypes),
277+
Config: types.MapNull(types.StringType),
278+
Security: types.ObjectNull(streamconnection.ConnectionSecurityObjectType.AttrTypes),
279+
DBRoleToExecute: types.ObjectNull(streamconnection.DBRoleToExecuteObjectType.AttrTypes),
280+
},
245281
},
246282
},
247283
},
@@ -349,6 +385,19 @@ func TestStreamInstanceTFToSDKCreateModel(t *testing.T) {
349385
Type: admin.PtrString("Kafka"),
350386
},
351387
},
388+
{
389+
name: "Sample type TF state",
390+
tfModel: &streamconnection.TFStreamConnectionModel{
391+
ProjectID: types.StringValue(dummyProjectID),
392+
InstanceName: types.StringValue(instanceName),
393+
ConnectionName: types.StringValue(connectionName),
394+
Type: types.StringValue("Sample"),
395+
},
396+
expectedSDKReq: &admin.StreamsConnection{
397+
Name: admin.PtrString(connectionName),
398+
Type: admin.PtrString("Sample"),
399+
},
400+
},
352401
}
353402

354403
for _, tc := range testCases {

internal/service/streamconnection/resource_stream_connection_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@ func TestAccStreamRSStreamConnection_cluster(t *testing.T) {
9898
})
9999
}
100100

101+
func TestAccStreamRSStreamConnection_sample(t *testing.T) {
102+
var (
103+
resourceName = "mongodbatlas_stream_connection.test"
104+
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
105+
projectName = acc.RandomProjectName()
106+
instanceName = acc.RandomName()
107+
sampleName = "sample_stream_solar"
108+
)
109+
resource.ParallelTest(t, resource.TestCase{
110+
PreCheck: func() { acc.PreCheckPreviewFlag(t); acc.PreCheckBasic(t) },
111+
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
112+
CheckDestroy: CheckDestroyStreamConnection,
113+
Steps: []resource.TestStep{
114+
{
115+
Config: sampleStreamConnectionConfig(orgID, projectName, instanceName, sampleName),
116+
Check: sampleStreamConnectionAttributeChecks(resourceName, instanceName, sampleName),
117+
},
118+
{
119+
ResourceName: resourceName,
120+
ImportStateIdFunc: checkStreamConnectionImportStateIDFunc(resourceName),
121+
ImportState: true,
122+
ImportStateVerify: true,
123+
},
124+
},
125+
})
126+
}
127+
101128
func kafkaStreamConnectionConfig(orgID, projectName, instanceName, username, password, bootstrapServers, configValue string, useSSL bool) string {
102129
projectAndStreamInstanceConfig := acc.StreamInstanceConfig(orgID, projectName, instanceName, "VIRGINIA_USA", "AWS")
103130
securityConfig := `
@@ -135,6 +162,33 @@ func kafkaStreamConnectionConfig(orgID, projectName, instanceName, username, pas
135162
`, projectAndStreamInstanceConfig, username, password, bootstrapServers, configValue, securityConfig)
136163
}
137164

165+
func sampleStreamConnectionConfig(orgID, projectName, instanceName, sampleName string) string {
166+
projectAndStreamInstanceConfig := acc.StreamInstanceConfig(orgID, projectName, instanceName, "VIRGINIA_USA", "AWS")
167+
168+
return fmt.Sprintf(`
169+
%[1]s
170+
171+
resource "mongodbatlas_stream_connection" "test" {
172+
project_id = mongodbatlas_project.test.id
173+
instance_name = mongodbatlas_stream_instance.test.instance_name
174+
connection_name = %[2]q
175+
type = "Sample"
176+
}
177+
`, projectAndStreamInstanceConfig, sampleName)
178+
}
179+
180+
func sampleStreamConnectionAttributeChecks(
181+
resourceName, instanceName, sampleName string) resource.TestCheckFunc {
182+
resourceChecks := []resource.TestCheckFunc{
183+
checkStreamConnectionExists(),
184+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
185+
resource.TestCheckResourceAttr(resourceName, "instance_name", instanceName),
186+
resource.TestCheckResourceAttr(resourceName, "connection_name", sampleName),
187+
resource.TestCheckResourceAttr(resourceName, "type", "Sample"),
188+
}
189+
return resource.ComposeTestCheckFunc(resourceChecks...)
190+
}
191+
138192
func kafkaStreamConnectionAttributeChecks(
139193
resourceName, orgID, projectName, instanceName, username, password, bootstrapServers, configValue string, usesSSL, checkPassword bool) resource.TestCheckFunc {
140194
resourceChecks := []resource.TestCheckFunc{

website/docs/d/stream_connection.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ data "mongodbatlas_stream_connection" "example" {
2626

2727
* `project_id` - (Required) Unique 24-hexadecimal digit string that identifies your project.
2828
* `instance_name` - (Required) Human-readable label that identifies the stream instance.
29-
* `connection_name` - (Required) Human-readable label that identifies the stream connection.
29+
* `connection_name` - (Required) Human-readable label that identifies the stream connection. In the case of the Sample type, this is the name of the sample source.
3030

3131
## Attributes Reference
3232

33-
* `type` - Type of connection. Can be either `Cluster` or `Kafka`.
33+
* `type` - Type of connection. Can be either `Cluster`, `Kafka` or `Sample`.
3434

3535
If `type` is of value `Cluster` the following additional attributes are defined:
3636
* `cluster_name` - Name of the cluster configured for this connection.

website/docs/d/stream_connections.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ In addition to all arguments above, it also exports the following attributes:
4141

4242
* `project_id` - Unique 24-hexadecimal digit string that identifies your project.
4343
* `instance_name` - Human-readable label that identifies the stream instance.
44-
* `connection_name` - Human-readable label that identifies the stream connection.
45-
* `type` - Type of connection. Can be either `Cluster` or `Kafka`.
44+
* `connection_name` - Human-readable label that identifies the stream connection. In the case of the Sample type, this is the name of the sample source.
45+
* `type` - Type of connection. Can be either `Cluster`, `Kafka` or `Sample`.
4646

4747
If `type` is of value `Cluster` the following additional attributes are defined:
4848
* `cluster_name` - Name of the cluster configured for this connection.

website/docs/r/stream_connection.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ resource "mongodbatlas_stream_connection" "test" {
8080

8181
* `project_id` - (Required) Unique 24-hexadecimal digit string that identifies your project.
8282
* `instance_name` - (Required) Human-readable label that identifies the stream instance.
83-
* `connection_name` - (Required) Human-readable label that identifies the stream connection.
84-
* `type` - (Required) Type of connection. Can be either `Cluster` or `Kafka`.
83+
* `connection_name` - (Required) Human-readable label that identifies the stream connection. In the case of the Sample type, this is the name of the sample source.
84+
* `type` - (Required) Type of connection. Can be either `Cluster`, `Kafka` or `Sample`.
8585

8686
If `type` is of value `Cluster` the following additional arguments are defined:
8787
* `cluster_name` - Name of the cluster configured for this connection.

0 commit comments

Comments
 (0)