Skip to content

Commit c23ced9

Browse files
authored
feat: Adds support for cluster_project_id field for stream_connection (#3424)
1 parent 42cf0c8 commit c23ced9

File tree

11 files changed

+85
-2
lines changed

11 files changed

+85
-2
lines changed

.changelog/3424.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
data-source/mongodbatlas_stream_connection Adds `cluster_project_id` to allow connections to clusters in other projects within an organization
3+
```
4+
5+
```release-note:enhancement
6+
resource/mongodbatlas_stream_connection Adds `cluster_project_id` to allow connections to clusters in other projects within an organization
7+
```

docs/data-sources/stream_connection.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ data "mongodbatlas_stream_connection" "example" {
2525
If `type` is of value `Cluster` the following additional attributes are defined:
2626
* `cluster_name` - Name of the cluster configured for this connection.
2727
* `db_role_to_execute` - The name of a Built in or Custom DB Role to connect to an Atlas Cluster. See [DBRoleToExecute](#DBRoleToExecute).
28+
* `cluster_project_id` - Unique 24-hexadecimal digit string that identifies the project that contains the configured cluster. Required if the ID does not match the project containing the streams instance. You must first enable the organization setting.
2829

2930
If `type` is of value `Kafka` the following additional attributes are defined:
3031
* `authentication` - User credentials required to connect to a Kafka cluster. Includes the authentication type, as well as the parameters for that authentication mode. See [authentication](#authentication).

docs/resources/stream_connection.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ resource "mongodbatlas_stream_connection" "test" {
1919
}
2020
```
2121

22+
### Example Cross Project Cluster Connection
23+
24+
```terraform
25+
resource "mongodbatlas_stream_connection" "test" {
26+
project_id = var.project_id
27+
instance_name = "InstanceName"
28+
connection_name = "ConnectionName"
29+
type = "Cluster"
30+
cluster_name = "OtherCluster"
31+
cluster_project_id = var.other_project_id
32+
}
33+
```
34+
2235
### Example Kafka SASL Plaintext Connection
2336

2437
```terraform
@@ -107,6 +120,7 @@ resource "mongodbatlas_stream_connection" "example-https" {
107120
If `type` is of value `Cluster` the following additional arguments are defined:
108121
* `cluster_name` - Name of the cluster configured for this connection.
109122
* `db_role_to_execute` - The name of a Built in or Custom DB Role to connect to an Atlas Cluster. See [DBRoleToExecute](#DBRoleToExecute).
123+
* `cluster_project_id` - Unique 24-hexadecimal digit string that identifies the project that contains the configured cluster. Required if the ID does not match the project containing the streams instance. You must first enable the organization setting.
110124

111125
If `type` is of value `Kafka` the following additional arguments are defined:
112126
* `authentication` - User credentials required to connect to a Kafka cluster. Includes the authentication type, as well as the parameters for that authentication mode. See [authentication](#authentication).

examples/mongodbatlas_stream_account_details/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
mongodbatlas = {
44
source = "mongodb/mongodbatlas"
5-
version = "~> 1.35"
5+
version = "~> 1.36"
66
}
77
}
88
required_version = ">= 1.0"

examples/mongodbatlas_stream_connection/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
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.
44

5-
You must set the following variables:
5+
You must set the following variables depending on connection type:
66

77
- `public_key`: Atlas public key
88
- `private_key`: Atlas private key
@@ -11,5 +11,6 @@ You must set the following variables:
1111
- `kafka_password`: Password used for connecting to your external Kafka Cluster.
1212
- `kafka_ssl_cert`: String value of public x509 certificate for connecting to Kafka over SSL.
1313
- `cluster_name`: Name of Cluster that will be used for creating a connection.
14+
- `cluster_project_id`: The project of the Cluster that will be used for creating a connection. Required if the project is different from the project of the stream instance.
1415

1516
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).

examples/mongodbatlas_stream_connection/main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ resource "mongodbatlas_stream_connection" "example-cluster" {
1919
}
2020
}
2121

22+
resource "mongodbatlas_stream_connection" "example-cross-project-cluster" {
23+
project_id = var.project_id
24+
instance_name = mongodbatlas_stream_instance.example.instance_name
25+
connection_name = "ClusterCrossProjectConnection"
26+
type = "Cluster"
27+
cluster_name = var.other_cluster
28+
cluster_project_id = var.other_project_id
29+
db_role_to_execute = {
30+
role = "atlasAdmin"
31+
type = "BUILT_IN"
32+
}
33+
}
34+
2235
resource "mongodbatlas_stream_connection" "example-kafka-plaintext" {
2336
project_id = var.project_id
2437
instance_name = mongodbatlas_stream_instance.example.instance_name

examples/mongodbatlas_stream_connection/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@ variable "kafka_ssl_cert" {
2929
variable "cluster_name" {
3030
description = "Name of an existing cluster in your project that will be used to create a stream connection"
3131
type = string
32+
}
33+
34+
variable "other_project_id" {
35+
description = "Unique 24-hexadecimal digit string that identifies another project with a cluster that can be connected"
36+
type = string
37+
}
38+
39+
variable "other_cluster" {
40+
description = "Name of an existing cluster in another project within an organization that will be used to create a stream connection"
41+
type = string
3242
}

internal/service/streamconnection/model_stream_connection.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func NewStreamConnectionReq(ctx context.Context, plan *TFStreamConnectionModel)
1717
Name: plan.ConnectionName.ValueStringPointer(),
1818
Type: plan.Type.ValueStringPointer(),
1919
ClusterName: plan.ClusterName.ValueStringPointer(),
20+
ClusterGroupId: plan.ClusterProjectID.ValueStringPointer(),
2021
BootstrapServers: plan.BootstrapServers.ValueStringPointer(),
2122
Url: plan.URL.ValueStringPointer(),
2223
}
@@ -125,6 +126,7 @@ func NewTFStreamConnection(ctx context.Context, projID, instanceName string, cur
125126
ConnectionName: types.StringPointerValue(apiResp.Name),
126127
Type: types.StringPointerValue(apiResp.Type),
127128
ClusterName: types.StringPointerValue(apiResp.ClusterName),
129+
ClusterProjectID: types.StringPointerValue(apiResp.ClusterGroupId),
128130
BootstrapServers: types.StringPointerValue(apiResp.BootstrapServers),
129131
URL: types.StringPointerValue(apiResp.Url),
130132
}

internal/service/streamconnection/model_stream_connection_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,37 @@ func TestStreamConnectionSDKToTFModel(t *testing.T) {
8181
Headers: types.MapNull(types.StringType),
8282
},
8383
},
84+
{
85+
name: "Cluster cross project connection type SDK response",
86+
SDKResp: &admin.StreamsConnection{
87+
Name: admin.PtrString(connectionName),
88+
Type: admin.PtrString("Cluster"),
89+
ClusterName: admin.PtrString(clusterName),
90+
ClusterGroupId: admin.PtrString("foo"),
91+
DbRoleToExecute: &admin.DBRoleToExecute{
92+
Role: admin.PtrString(dbRole),
93+
Type: admin.PtrString(dbRoleType),
94+
},
95+
},
96+
providedProjID: dummyProjectID,
97+
providedInstanceName: instanceName,
98+
providedAuthConfig: nil,
99+
expectedTFModel: &streamconnection.TFStreamConnectionModel{
100+
ProjectID: types.StringValue(dummyProjectID),
101+
InstanceName: types.StringValue(instanceName),
102+
ConnectionName: types.StringValue(connectionName),
103+
Type: types.StringValue("Cluster"),
104+
ClusterName: types.StringValue(clusterName),
105+
ClusterProjectID: types.StringValue("foo"),
106+
Authentication: types.ObjectNull(streamconnection.ConnectionAuthenticationObjectType.AttrTypes),
107+
Config: types.MapNull(types.StringType),
108+
Security: types.ObjectNull(streamconnection.ConnectionSecurityObjectType.AttrTypes),
109+
DBRoleToExecute: tfDBRoleToExecuteObject(t, dbRole, dbRoleType),
110+
Networking: types.ObjectNull(streamconnection.NetworkingObjectType.AttrTypes),
111+
AWS: types.ObjectNull(streamconnection.AWSObjectType.AttrTypes),
112+
Headers: types.MapNull(types.StringType),
113+
},
114+
},
84115
{
85116
name: "Kafka connection type SDK response",
86117
SDKResp: &admin.StreamsConnection{

internal/service/streamconnection/resource_schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func ResourceSchema(ctx context.Context) schema.Schema {
5050
"cluster_name": schema.StringAttribute{
5151
Optional: true,
5252
},
53+
"cluster_project_id": schema.StringAttribute{
54+
Optional: true,
55+
},
5356
"db_role_to_execute": schema.SingleNestedAttribute{
5457
Optional: true,
5558
Attributes: map[string]schema.Attribute{

0 commit comments

Comments
 (0)