Skip to content

Commit

Permalink
feat: Adds support for Sample stream type to mongodbatlas_stream_conn…
Browse files Browse the repository at this point in the history
…ection (#2026)
  • Loading branch information
maastha authored Mar 13, 2024
1 parent 917da62 commit 958c6de
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 21 deletions.
7 changes: 7 additions & 0 deletions examples/mongodbatlas_stream_connection/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ resource "mongodbatlas_stream_connection" "example-kafka-ssl" {
}
}

resource "mongodbatlas_stream_connection" "example-sample" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "sample_stream_solar"
type = "Sample"
}

data "mongodbatlas_stream_connection" "example-kafka-ssl" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ func TestAccStreamDSStreamConnection_cluster(t *testing.T) {
})
}

func TestAccStreamDSStreamConnection_sample(t *testing.T) {
var (
dataSourceName = "data.mongodbatlas_stream_connection.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
instanceName = acc.RandomName()
sampleName = "sample_stream_solar"
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckPreviewFlag(t); acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: CheckDestroyStreamConnection,
Steps: []resource.TestStep{
{
Config: streamConnectionDataSourceConfig(sampleStreamConnectionConfig(orgID, projectName, instanceName, sampleName)),
Check: sampleStreamConnectionAttributeChecks(dataSourceName, instanceName, sampleName),
},
},
})
}

func streamConnectionDataSourceConfig(streamConnectionConfig string) string {
return fmt.Sprintf(`
%s
Expand Down
79 changes: 64 additions & 15 deletions internal/service/streamconnection/model_stream_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import (
)

const (
connectionName = "Connection"
typeValue = ""
clusterName = "Cluster0"
dummyProjectID = "111111111111111111111111"
instanceName = "InstanceName"
authMechanism = "PLAIN"
authUsername = "user1"
securityProtocol = "SSL"
bootstrapServers = "localhost:9092,another.host:9092"
dbRole = "customRole"
dbRoleType = "CUSTOM"
connectionName = "Connection"
typeValue = ""
clusterName = "Cluster0"
dummyProjectID = "111111111111111111111111"
instanceName = "InstanceName"
authMechanism = "PLAIN"
authUsername = "user1"
securityProtocol = "SSL"
bootstrapServers = "localhost:9092,another.host:9092"
dbRole = "customRole"
dbRoleType = "CUSTOM"
sampleConnectionName = "sample_stream_solar"
)

var configMap = map[string]string{
Expand Down Expand Up @@ -150,6 +151,25 @@ func TestStreamConnectionSDKToTFModel(t *testing.T) {
DBRoleToExecute: types.ObjectNull(streamconnection.DBRoleToExecuteObjectType.AttrTypes),
},
},
{
name: "Sample connection type sample_stream_solar sample",
SDKResp: &admin.StreamsConnection{
Name: admin.PtrString(sampleConnectionName),
Type: admin.PtrString("Sample"),
},
providedProjID: dummyProjectID,
providedInstanceName: instanceName,
expectedTFModel: &streamconnection.TFStreamConnectionModel{
ProjectID: types.StringValue(dummyProjectID),
InstanceName: types.StringValue(instanceName),
ConnectionName: types.StringValue(sampleConnectionName),
Type: types.StringValue("Sample"),
Authentication: types.ObjectNull(streamconnection.ConnectionAuthenticationObjectType.AttrTypes),
Config: types.MapNull(types.StringType),
Security: types.ObjectNull(streamconnection.ConnectionSecurityObjectType.AttrTypes),
DBRoleToExecute: types.ObjectNull(streamconnection.DBRoleToExecuteObjectType.AttrTypes),
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -202,21 +222,25 @@ func TestStreamConnectionsSDKToTFModel(t *testing.T) {
Type: admin.PtrString(dbRoleType),
},
},
{
Name: admin.PtrString(sampleConnectionName),
Type: admin.PtrString("Sample"),
},
},
TotalCount: admin.PtrInt(2),
TotalCount: admin.PtrInt(3),
},
providedConfig: &streamconnection.TFStreamConnectionsDSModel{
ProjectID: types.StringValue(dummyProjectID),
InstanceName: types.StringValue(instanceName),
PageNum: types.Int64Value(1),
ItemsPerPage: types.Int64Value(2),
ItemsPerPage: types.Int64Value(3),
},
expectedTFModel: &streamconnection.TFStreamConnectionsDSModel{
ProjectID: types.StringValue(dummyProjectID),
InstanceName: types.StringValue(instanceName),
PageNum: types.Int64Value(1),
ItemsPerPage: types.Int64Value(2),
TotalCount: types.Int64Value(2),
ItemsPerPage: types.Int64Value(3),
TotalCount: types.Int64Value(3),
Results: []streamconnection.TFStreamConnectionModel{
{
ID: types.StringValue(fmt.Sprintf("%s-%s-%s", instanceName, dummyProjectID, connectionName)),
Expand All @@ -242,6 +266,18 @@ func TestStreamConnectionsSDKToTFModel(t *testing.T) {
Security: types.ObjectNull(streamconnection.ConnectionSecurityObjectType.AttrTypes),
DBRoleToExecute: tfDBRoleToExecuteObject(t, dbRole, dbRoleType),
},
{
ID: types.StringValue(fmt.Sprintf("%s-%s-%s", instanceName, dummyProjectID, sampleConnectionName)),
ProjectID: types.StringValue(dummyProjectID),
InstanceName: types.StringValue(instanceName),
ConnectionName: types.StringValue(sampleConnectionName),
Type: types.StringValue("Sample"),
ClusterName: types.StringNull(),
Authentication: types.ObjectNull(streamconnection.ConnectionAuthenticationObjectType.AttrTypes),
Config: types.MapNull(types.StringType),
Security: types.ObjectNull(streamconnection.ConnectionSecurityObjectType.AttrTypes),
DBRoleToExecute: types.ObjectNull(streamconnection.DBRoleToExecuteObjectType.AttrTypes),
},
},
},
},
Expand Down Expand Up @@ -349,6 +385,19 @@ func TestStreamInstanceTFToSDKCreateModel(t *testing.T) {
Type: admin.PtrString("Kafka"),
},
},
{
name: "Sample type TF state",
tfModel: &streamconnection.TFStreamConnectionModel{
ProjectID: types.StringValue(dummyProjectID),
InstanceName: types.StringValue(instanceName),
ConnectionName: types.StringValue(connectionName),
Type: types.StringValue("Sample"),
},
expectedSDKReq: &admin.StreamsConnection{
Name: admin.PtrString(connectionName),
Type: admin.PtrString("Sample"),
},
},
}

for _, tc := range testCases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ func TestAccStreamRSStreamConnection_cluster(t *testing.T) {
})
}

func TestAccStreamRSStreamConnection_sample(t *testing.T) {
var (
resourceName = "mongodbatlas_stream_connection.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
instanceName = acc.RandomName()
sampleName = "sample_stream_solar"
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckPreviewFlag(t); acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: CheckDestroyStreamConnection,
Steps: []resource.TestStep{
{
Config: sampleStreamConnectionConfig(orgID, projectName, instanceName, sampleName),
Check: sampleStreamConnectionAttributeChecks(resourceName, instanceName, sampleName),
},
{
ResourceName: resourceName,
ImportStateIdFunc: checkStreamConnectionImportStateIDFunc(resourceName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func kafkaStreamConnectionConfig(orgID, projectName, instanceName, username, password, bootstrapServers, configValue string, useSSL bool) string {
projectAndStreamInstanceConfig := acc.StreamInstanceConfig(orgID, projectName, instanceName, "VIRGINIA_USA", "AWS")
securityConfig := `
Expand Down Expand Up @@ -135,6 +162,33 @@ func kafkaStreamConnectionConfig(orgID, projectName, instanceName, username, pas
`, projectAndStreamInstanceConfig, username, password, bootstrapServers, configValue, securityConfig)
}

func sampleStreamConnectionConfig(orgID, projectName, instanceName, sampleName string) string {
projectAndStreamInstanceConfig := acc.StreamInstanceConfig(orgID, projectName, instanceName, "VIRGINIA_USA", "AWS")

return fmt.Sprintf(`
%[1]s
resource "mongodbatlas_stream_connection" "test" {
project_id = mongodbatlas_project.test.id
instance_name = mongodbatlas_stream_instance.test.instance_name
connection_name = %[2]q
type = "Sample"
}
`, projectAndStreamInstanceConfig, sampleName)
}

func sampleStreamConnectionAttributeChecks(
resourceName, instanceName, sampleName string) resource.TestCheckFunc {
resourceChecks := []resource.TestCheckFunc{
checkStreamConnectionExists(),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "instance_name", instanceName),
resource.TestCheckResourceAttr(resourceName, "connection_name", sampleName),
resource.TestCheckResourceAttr(resourceName, "type", "Sample"),
}
return resource.ComposeTestCheckFunc(resourceChecks...)
}

func kafkaStreamConnectionAttributeChecks(
resourceName, orgID, projectName, instanceName, username, password, bootstrapServers, configValue string, usesSSL, checkPassword bool) resource.TestCheckFunc {
resourceChecks := []resource.TestCheckFunc{
Expand Down
4 changes: 2 additions & 2 deletions website/docs/d/stream_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ data "mongodbatlas_stream_connection" "example" {

* `project_id` - (Required) Unique 24-hexadecimal digit string that identifies your project.
* `instance_name` - (Required) Human-readable label that identifies the stream instance.
* `connection_name` - (Required) Human-readable label that identifies the stream connection.
* `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.

## Attributes Reference

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

If `type` is of value `Cluster` the following additional attributes are defined:
* `cluster_name` - Name of the cluster configured for this connection.
Expand Down
4 changes: 2 additions & 2 deletions website/docs/d/stream_connections.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ In addition to all arguments above, it also exports the following attributes:

* `project_id` - Unique 24-hexadecimal digit string that identifies your project.
* `instance_name` - Human-readable label that identifies the stream instance.
* `connection_name` - Human-readable label that identifies the stream connection.
* `type` - Type of connection. Can be either `Cluster` or `Kafka`.
* `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.
* `type` - Type of connection. Can be either `Cluster`, `Kafka` or `Sample`.

If `type` is of value `Cluster` the following additional attributes are defined:
* `cluster_name` - Name of the cluster configured for this connection.
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/stream_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ resource "mongodbatlas_stream_connection" "test" {

* `project_id` - (Required) Unique 24-hexadecimal digit string that identifies your project.
* `instance_name` - (Required) Human-readable label that identifies the stream instance.
* `connection_name` - (Required) Human-readable label that identifies the stream connection.
* `type` - (Required) Type of connection. Can be either `Cluster` or `Kafka`.
* `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.
* `type` - (Required) Type of connection. Can be either `Cluster`, `Kafka` or `Sample`.

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

0 comments on commit 958c6de

Please sign in to comment.