Skip to content

Commit 350534c

Browse files
feat: new mongodbatlas_stream_connection resource (#1736)
* feat: new mongodbatlas_stream_connection resource * define dummy ca cert in external file and embed into variable for testing * fix content of id * refactor: avoid depending on existing project for CI tests in search index and stream connection resources (#1737) * refactor: common cluster config funtion avoids depending on existing project * define return value as struct and unify comments * doc: `mongodbatlas_stream_connection` resource docs, examples, and general Atlas Streams guide (#1752) * docs: stream connection resource docs and examples * addressing doc review comments * fix yaml formatting in header + examples mentioning limitations
1 parent 8293bb5 commit 350534c

26 files changed

+1399
-170
lines changed

.github/workflows/acceptance-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
- 'internal/service/searchdeployment/*.go'
6969
stream:
7070
- 'internal/service/streaminstance/*.go'
71+
- 'internal/service/streamconnection/*.go'
7172
generic:
7273
- 'internal/service/backupcompliancepolicy/*.go'
7374
- 'internal/service/auditing/*.go'
@@ -528,7 +529,6 @@ jobs:
528529
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
529530
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
530531
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
531-
MONGODB_ATLAS_PROJECT_ID: ${{ vars.MONGODB_ATLAS_ACCTEST_SEARCH_INDEX_PROJECT_ID_CLOUD_DEV }}
532532
TEST_REGEX: "^TestAccSearchIndex"
533533
run: make testacc
534534

examples/atlas-streams/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MongoDB Atlas Provider - Atlas Streams with Terraform
2+
3+
Atlas Stream Processing is composed of multiple components, and users can leverage Terraform to define a subset of these. To obtain more details on each of the components please refer to the [Atlas Stream Processing Documentation](https://www.mongodb.com/docs/atlas/atlas-sp/overview/#atlas-stream-processing-overview).
4+
5+
### Resources supported by Terraform
6+
7+
- `mongodbatlas_stream_instance`: Enables creating, modifying, and deleting Stream Instances. as part of this resource, a computed `hostnames` attribute is available for connecting to the created instance.
8+
- `mongodbatlas_stream_connection`: Enables creating, modifying, and deleting Stream Instance Connections, which serve as data sources and sinks for your instance.
9+
10+
**NOTE**: To leverage these resources you'll need to set the environment variable `MONGODB_ATLAS_ENABLE_BETA=true` as this functionality is currently in preview. Also see [Limitations](https://www.mongodb.com/docs/atlas/atlas-sp/limitations/#std-label-atlas-sp-limitations) of Atlas Streams during this preview period.
11+
12+
### Managing Stream Processors
13+
14+
Once a stream instance and its connections have been defined, `Stream Processors` can be created to define how your data will be processed in your instance. There are currently no resources defined in Terraform to provide this configuration. To obtain information on how this can be configured refer to [Manage Stream Processors](https://www.mongodb.com/docs/atlas/atlas-sp/manage-stream-processor/#manage-stream-processors).
15+
16+
Connect to your stream instance defined in terraform using the following code block:
17+
```
18+
output "stream_instance_hostname" {
19+
value = mongodbatlas_stream_instance.test.hostnames
20+
}
21+
```
22+
23+
This value can then be used to connect to the stream instance using `mongosh`, as described in the [Get Started Tutorial](https://www.mongodb.com/docs/atlas/atlas-sp/tutorial/).
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# MongoDB Atlas Provider - Atlas Stream Instance defined in a Project
2+
3+
This example shows how to create Atlas Stream Connections in Terraform. It also creates a stream instance, which is a prerequisite. Both Kafka and Cluster connections types are defined to showcase their usage.
4+
5+
You must set the following variables:
6+
7+
- `public_key`: Atlas public key
8+
- `private_key`: Atlas private key
9+
- `project_id`: Unique 24-hexadecimal digit string that identifies the project where the stream instance will be created.
10+
- `kafka_username`: Username used for connecting to your external Kafka Cluster.
11+
- `kafka_password`: Password used for connecting to your external Kafka Cluster.
12+
- `kafka_ssl_cert`: String value of public x509 certificate for connecting to Kafka over SSL.
13+
- `cluster_name`: Name of Cluster that will be used for creating a connection.
14+
15+
To learn more, see the [Stream Instance Connection Registry Documentation](https://www.mongodb.com/docs/atlas/atlas-sp/manage-processing-instance/#view-connections-in-the-connection-registry).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
resource "mongodbatlas_stream_instance" "example" {
2+
project_id = var.project_id
3+
instance_name = "InstanceName"
4+
data_process_region = {
5+
region = "VIRGINIA_USA"
6+
cloud_provider = "AWS"
7+
}
8+
}
9+
10+
resource "mongodbatlas_stream_connection" "example-cluster" {
11+
project_id = var.project_id
12+
instance_name = mongodbatlas_stream_instance.example.instance_name
13+
connection_name = "ClusterConnection"
14+
type = "Cluster"
15+
cluster_name = var.cluster_name
16+
}
17+
18+
resource "mongodbatlas_stream_connection" "example-kafka-plaintext" {
19+
project_id = var.project_id
20+
instance_name = mongodbatlas_stream_instance.example.instance_name
21+
connection_name = "KafkaPlaintextConnection"
22+
type = "Kafka"
23+
authentication = {
24+
mechanism = "PLAIN"
25+
username = var.kafka_username
26+
password = var.kafka_password
27+
}
28+
bootstrap_servers = "localhost:9092,localhost:9092"
29+
config = {
30+
"auto.offset.reset" : "earliest"
31+
}
32+
security = {
33+
protocol = "PLAINTEXT"
34+
}
35+
}
36+
37+
resource "mongodbatlas_stream_connection" "example-kafka-ssl" {
38+
project_id = var.project_id
39+
instance_name = mongodbatlas_stream_instance.example.instance_name
40+
connection_name = "KafkaSSLConnection"
41+
type = "Kafka"
42+
authentication = {
43+
mechanism = "PLAIN"
44+
username = var.kafka_username
45+
password = var.kafka_password
46+
}
47+
bootstrap_servers = "localhost:9092,localhost:9092"
48+
config = {
49+
"auto.offset.reset" : "earliest"
50+
}
51+
security = {
52+
broker_public_certificate = var.kafka_ssl_cert
53+
protocol = "SSL"
54+
}
55+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 "project_id" {
10+
description = "Unique 24-hexadecimal digit string that identifies your project"
11+
type = string
12+
}
13+
14+
variable "kafka_username" {
15+
description = "Username for connecting to your Kafka cluster"
16+
type = string
17+
}
18+
19+
variable "kafka_password" {
20+
description = "Password for connecting to your Kafka cluster"
21+
type = string
22+
}
23+
24+
variable "kafka_ssl_cert" {
25+
description = "Public certificate used for SSL configuration to connect to your Kafka cluster"
26+
type = string
27+
}
28+
29+
variable "cluster_name" {
30+
description = "Name of an existing cluster in your project that will be used to create a stream connection"
31+
type = string
32+
}
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.14"
6+
}
7+
}
8+
required_version = ">= 1.0"
9+
}

internal/provider/provider.go

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/project"
3434
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectipaccesslist"
3535
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchdeployment"
36+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streamconnection"
3637
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streaminstance"
3738

3839
"github.com/mongodb/terraform-provider-mongodbatlas/version"
@@ -435,6 +436,7 @@ func (p *MongodbtlasProvider) Resources(context.Context) []func() resource.Resou
435436
}
436437
betaResources := []func() resource.Resource{
437438
streaminstance.Resource,
439+
streamconnection.Resource,
438440
}
439441
if ProviderEnableBeta {
440442
resources = append(resources, betaResources...)

0 commit comments

Comments
 (0)