Skip to content

Commit 1958e51

Browse files
authored
feat: Supports new Https connection type in streams processing (#3150)
1 parent cb57c1a commit 1958e51

File tree

12 files changed

+297
-52
lines changed

12 files changed

+297
-52
lines changed

.changelog/3150.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
resource/mongodbatlas_stream_connection: Adds `Https` connection
3+
```
4+
5+
```release-note:enhancement
6+
data-source/mongodbatlas_stream_connection: Adds `Https` connection
7+
```
8+
9+
```release-note:enhancement
10+
data-source/mongodbatlas_stream_connections: Adds `Https` connection
11+
```

docs/data-sources/stream_connection.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data "mongodbatlas_stream_connection" "example" {
2020

2121
## Attributes Reference
2222

23-
* `type` - Type of connection. Can be `Cluster`, `Kafka`, `Sample`, or `AWSLambda`.
23+
* `type` - Type of connection. Can be `AWSLambda`, `Cluster`, `Https`, `Kafka` or `Sample`.
2424

2525
If `type` is of value `Cluster` the following additional attributes are defined:
2626
* `cluster_name` - Name of the cluster configured for this connection.
@@ -36,6 +36,10 @@ If `type` is of value `Kafka` the following additional attributes are defined:
3636
If `type` is of value `AWSLambda` the following additional attributes are defined:
3737
* `aws` - The configuration for AWS Lambda connection. See [AWS](#AWS)
3838

39+
If `type` is of value `Https` the following additional attributes are defined:
40+
* `url` - URL of the HTTPs endpoint that will be used for creating a connection.
41+
* `headers` - A map of key-value pairs for optional headers.
42+
3943
### Authentication
4044

4145
* `mechanism` - Style of authentication. Can be one of `PLAIN`, `SCRAM-256`, or `SCRAM-512`.

docs/data-sources/stream_connections.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ In addition to all arguments above, it also exports the following attributes:
3232
* `project_id` - Unique 24-hexadecimal digit string that identifies your project.
3333
* `instance_name` - Human-readable label that identifies the stream instance.
3434
* `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.
35-
* `type` - Type of connection. `Cluster`, `Kafka`, `Sample`, or `AWSLambda`.
35+
* `type` - Type of connection. `AWSLambda`, `Cluster`, `Https`, `Kafka` or `Sample`.
3636

3737
If `type` is of value `Cluster` the following additional attributes are defined:
3838
* `cluster_name` - Name of the cluster configured for this connection.
@@ -48,6 +48,10 @@ If `type` is of value `Kafka` the following additional attributes are defined:
4848
If `type` is of value `AWSLambda` the following additional attributes are defined::
4949
* `aws` - The configuration for AWS Lambda connection. See [AWS](#AWS)
5050

51+
If `type` is of value `Https` the following additional attributes are defined:
52+
* `url` - URL of the HTTPs endpoint that will be used for creating a connection.
53+
* `headers` - A map of key-value pairs for optional headers.
54+
5155
### Authentication
5256

5357
* `mechanism` - Style of authentication. Can be one of `PLAIN`, `SCRAM-256`, or `SCRAM-512`.

docs/resources/stream_connection.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,28 @@ resource "mongodbatlas_stream_connection" "test" {
8181
8282
```
8383

84+
### Example Https Connection
85+
86+
```terraform
87+
resource "mongodbatlas_stream_connection" "example-https" {
88+
project_id = var.project_id
89+
instance_name = mongodbatlas_stream_instance.example.instance_name
90+
connection_name = "https_connection_tf_new"
91+
type = "Https"
92+
url = "https://example.com"
93+
headers = {
94+
key1 = "value1"
95+
key2 = "value2"
96+
}
97+
}
98+
```
99+
84100
## Argument Reference
85101

86102
* `project_id` - (Required) Unique 24-hexadecimal digit string that identifies your project.
87103
* `instance_name` - (Required) Human-readable label that identifies the stream instance.
88104
* `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.
89-
* `type` - (Required) Type of connection. Can be `Cluster`, `Kafka`, `Sample`, or `AWSLambda`.
105+
* `type` - (Required) Type of connection. Can be `AWSLambda`, `Cluster`, `Https`, `Kafka` or `Sample`.
90106

91107
If `type` is of value `Cluster` the following additional arguments are defined:
92108
* `cluster_name` - Name of the cluster configured for this connection.
@@ -102,6 +118,10 @@ If `type` is of value `Kafka` the following additional arguments are defined:
102118
If `type` is of value `AWSLambda` the following additional arguments are defined:
103119
* `aws` - The configuration for AWS Lambda connection. See [AWS](#AWS)
104120

121+
If `type` is of value `Https` the following additional attributes are defined:
122+
* `url` - URL of the HTTPs endpoint that will be used for creating a connection.
123+
* `headers` - A map of key-value pairs for optional headers.
124+
105125
### Authentication
106126

107127
* `mechanism` - Style of authentication. Can be one of `PLAIN`, `SCRAM-256`, or `SCRAM-512`.

examples/mongodbatlas_stream_connection/main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ resource "mongodbatlas_stream_connection" "example-aws-lambda" {
8080
}
8181
}
8282

83+
resource "mongodbatlas_stream_connection" "example-https" {
84+
project_id = var.project_id
85+
instance_name = mongodbatlas_stream_instance.example.instance_name
86+
connection_name = "HttpsConnection"
87+
type = "Https"
88+
url = "https://example.com"
89+
headers = {
90+
key1 = "value1"
91+
key2 = "value2"
92+
}
93+
}
94+
8395
data "mongodbatlas_stream_connection" "example-kafka-ssl" {
8496
project_id = var.project_id
8597
instance_name = mongodbatlas_stream_instance.example.instance_name

internal/service/streamconnection/data_source_stream_connection_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func TestAccStreamDSStreamConnection_kafkaPlaintext(t *testing.T) {
2020
CheckDestroy: CheckDestroyStreamConnection,
2121
Steps: []resource.TestStep{
2222
{
23-
Config: streamConnectionDataSourceConfig(kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", kafkaNetworkingPublic, false)),
24-
Check: kafkaStreamConnectionAttributeChecks(dataSourceName, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", networkingTypePublic, false, false),
23+
Config: streamConnectionDataSourceConfig(configureKafka(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", kafkaNetworkingPublic, false)),
24+
Check: checkKafkaAttributes(dataSourceName, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", networkingTypePublic, false, false),
2525
},
2626
},
2727
})
@@ -39,8 +39,8 @@ func TestAccStreamDSStreamConnection_kafkaSSL(t *testing.T) {
3939
CheckDestroy: CheckDestroyStreamConnection,
4040
Steps: []resource.TestStep{
4141
{
42-
Config: streamConnectionDataSourceConfig(kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092", "earliest", kafkaNetworkingPublic, true)),
43-
Check: kafkaStreamConnectionAttributeChecks(dataSourceName, instanceName, "user", "rawpassword", "localhost:9092", "earliest", networkingTypePublic, true, false),
42+
Config: streamConnectionDataSourceConfig(configureKafka(projectID, instanceName, "user", "rawpassword", "localhost:9092", "earliest", kafkaNetworkingPublic, true)),
43+
Check: checkKafkaAttributes(dataSourceName, instanceName, "user", "rawpassword", "localhost:9092", "earliest", networkingTypePublic, true, false),
4444
},
4545
},
4646
})
@@ -58,8 +58,8 @@ func TestAccStreamDSStreamConnection_cluster(t *testing.T) {
5858
CheckDestroy: CheckDestroyStreamConnection,
5959
Steps: []resource.TestStep{
6060
{
61-
Config: streamConnectionDataSourceConfig(clusterStreamConnectionConfig(projectID, instanceName, clusterName)),
62-
Check: clusterStreamConnectionAttributeChecks(dataSourceName, clusterName),
61+
Config: streamConnectionDataSourceConfig(configureCluster(projectID, instanceName, clusterName)),
62+
Check: checkClusterAttributes(dataSourceName, clusterName),
6363
},
6464
},
6565
})
@@ -78,8 +78,8 @@ func TestAccStreamDSStreamConnection_sample(t *testing.T) {
7878
CheckDestroy: CheckDestroyStreamConnection,
7979
Steps: []resource.TestStep{
8080
{
81-
Config: streamConnectionDataSourceConfig(sampleStreamConnectionConfig(projectID, instanceName, sampleName)),
82-
Check: sampleStreamConnectionAttributeChecks(dataSourceName, instanceName, sampleName),
81+
Config: streamConnectionDataSourceConfig(configureSampleStream(projectID, instanceName, sampleName)),
82+
Check: checkSampleStreamAttributes(dataSourceName, instanceName, sampleName),
8383
},
8484
},
8585
})

internal/service/streamconnection/data_source_stream_connections_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestAccStreamDSStreamConnections_basic(t *testing.T) {
2121
CheckDestroy: CheckDestroyStreamConnection,
2222
Steps: []resource.TestStep{
2323
{
24-
Config: streamConnectionsDataSourceConfig(kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", kafkaNetworkingPublic, false)),
24+
Config: streamConnectionsDataSourceConfig(configureKafka(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", kafkaNetworkingPublic, false)),
2525
Check: streamConnectionsAttributeChecks(dataSourceName, nil, nil, 1),
2626
},
2727
},
@@ -40,7 +40,7 @@ func TestAccStreamDSStreamConnections_withPageConfig(t *testing.T) {
4040
CheckDestroy: CheckDestroyStreamConnection,
4141
Steps: []resource.TestStep{
4242
{
43-
Config: streamConnectionsWithPageAttrDataSourceConfig(kafkaStreamConnectionConfig(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", kafkaNetworkingPublic, false)),
43+
Config: streamConnectionsWithPageAttrDataSourceConfig(configureKafka(projectID, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", kafkaNetworkingPublic, false)),
4444
Check: streamConnectionsAttributeChecks(dataSourceName, admin.PtrInt(2), admin.PtrInt(1), 0),
4545
},
4646
},

internal/service/streamconnection/model_stream_connection.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func NewStreamConnectionReq(ctx context.Context, plan *TFStreamConnectionModel)
1818
Type: plan.Type.ValueStringPointer(),
1919
ClusterName: plan.ClusterName.ValueStringPointer(),
2020
BootstrapServers: plan.BootstrapServers.ValueStringPointer(),
21+
Url: plan.URL.ValueStringPointer(),
2122
}
2223
if !plan.Authentication.IsNull() {
2324
authenticationModel := &TFConnectionAuthenticationModel{}
@@ -87,9 +88,34 @@ func NewStreamConnectionReq(ctx context.Context, plan *TFStreamConnectionModel)
8788
}
8889
}
8990

91+
if !plan.Headers.IsNull() {
92+
headersMap := make(map[string]string)
93+
if diags := plan.Headers.ElementsAs(ctx, &headersMap, true); diags.HasError() {
94+
return nil, diags
95+
}
96+
streamConnection.Headers = &headersMap
97+
}
98+
9099
return &streamConnection, nil
91100
}
92101

102+
func NewStreamConnectionUpdateReq(ctx context.Context, plan *TFStreamConnectionModel) (*admin.StreamsConnection, diag.Diagnostics) {
103+
streamConnection, diags := NewStreamConnectionReq(ctx, plan)
104+
if diags.HasError() {
105+
return nil, diags
106+
}
107+
108+
headersMap := make(map[string]string)
109+
// only set headers if the plan is not empty, otherwise the headers will be removed by sending an empty headers map to the PATCH endpoint
110+
if !plan.Headers.IsNull() && !plan.Headers.IsUnknown() {
111+
if diags := plan.Headers.ElementsAs(ctx, &headersMap, true); diags.HasError() {
112+
return nil, diags
113+
}
114+
}
115+
streamConnection.Headers = &headersMap
116+
return streamConnection, nil
117+
}
118+
93119
func NewTFStreamConnection(ctx context.Context, projID, instanceName string, currAuthConfig *types.Object, apiResp *admin.StreamsConnection) (*TFStreamConnectionModel, diag.Diagnostics) {
94120
rID := fmt.Sprintf("%s-%s-%s", instanceName, projID, conversion.SafeString(apiResp.Name))
95121
connectionModel := TFStreamConnectionModel{
@@ -100,6 +126,7 @@ func NewTFStreamConnection(ctx context.Context, projID, instanceName string, cur
100126
Type: types.StringPointerValue(apiResp.Type),
101127
ClusterName: types.StringPointerValue(apiResp.ClusterName),
102128
BootstrapServers: types.StringPointerValue(apiResp.BootstrapServers),
129+
URL: types.StringPointerValue(apiResp.Url),
103130
}
104131

105132
authModel, diags := newTFConnectionAuthenticationModel(ctx, currAuthConfig, apiResp.Authentication)
@@ -170,6 +197,16 @@ func NewTFStreamConnection(ctx context.Context, projID, instanceName string, cur
170197
connectionModel.AWS = aws
171198
}
172199

200+
connectionModel.Headers = types.MapNull(types.StringType)
201+
// this is to handle the case where empty headers are returned as an empty map from the API, which is equivalent to a null value
202+
if apiResp.Headers != nil && len(*apiResp.Headers) > 0 {
203+
mapValue, diags := types.MapValueFrom(ctx, types.StringType, apiResp.Headers)
204+
if diags.HasError() {
205+
return nil, diags
206+
}
207+
connectionModel.Headers = mapValue
208+
}
209+
173210
return &connectionModel, nil
174211
}
175212

0 commit comments

Comments
 (0)