Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changelog/3610.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/mongodbatlas_stream_connection: Adds workspace_name field as alias for instance_name.
```

```release-note:enhancement
data-source/mongodbatlas_stream_connection: Adds support for GCP as a Cloud Provider.
```

```release-note:enhancement
data-source/mongodbatlas_stream_connections: Adds support for GCP as a Cloud Provider.
```
17 changes: 15 additions & 2 deletions docs/data-sources/stream_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,30 @@ subcategory: "Streams"
```terraform
data "mongodbatlas_stream_connection" "example" {
project_id = "<PROJECT_ID>"
instance_name = "<INSTANCE_NAME>"
workspace_name = "<WORKSPACE_NAME>"
connection_name = "<CONNECTION_NAME>"
}
```

### Example using workspace_name

```terraform
data "mongodbatlas_stream_connection" "example" {
project_id = "<PROJECT_ID>"
workspace_name = "<WORKSPACE_NAME>"
connection_name = "<CONNECTION_NAME>"
}
```

## Argument Reference

* `project_id` - (Required) Unique 24-hexadecimal digit string that identifies your project.
* `instance_name` - (Required) Human-readable label that identifies the stream instance.
* `instance_name` - (Deprecated) Human-readable label that identifies the stream instance. Attribute is deprecated and will be removed in version 3.0.0 in favor of `workspace_name`.
* `workspace_name` - (Optional) Human-readable label that identifies the stream instance. Conflicts with `workspace_name`.
* `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.

~> **NOTE:** Either `workspace_name` or `workspace_name` must be provided, but not both. These fields are functionally identical and `workspace_name` is an alias for `workspace_name`. `workspace_name` should be used instead of `workspace_name`.

## Attributes Reference

* `type` - Type of connection. Can be `AWSLambda`, `Cluster`, `Https`, `Kafka` or `Sample`.
Expand Down
9 changes: 6 additions & 3 deletions docs/data-sources/stream_connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ subcategory: "Streams"
```terraform
data "mongodbatlas_stream_connections" "test" {
project_id = "<PROJECT_ID>"
instance_name = "<INSTANCE_NAME>"
workspace_name = "<WORKSPACE_NAME>"
}
```

## Argument Reference

* `project_id` - (Required) Unique 24-hexadecimal digit string that identifies your project.
* `instance_name` - (Required) Human-readable label that identifies the stream instance.
* `instance_name` - (Deprecated) Human-readable label that identifies the stream instance. Attribute is deprecated and will be removed in version 3.0.0 in favor of `workspace_name`.
* `workspace_name` - (Optional) Human-readable label that identifies the stream instance. Conflicts with `instance_name`.

~> **NOTE:** Either `instance_name` or `workspace_name` must be provided, but not both. These fields are functionally identical and `workspace_name` is an alias for `instance_name`. `workspace_name` should be used instead of `instance_name`.

* `page_num` - (Optional) Number of the page that displays the current set of the total objects that the response returns. Defaults to `1`.
* `items_per_page` - (Optional) Number of items that the response returns per page, up to a maximum of `500`. Defaults to `100`.
Expand All @@ -34,7 +37,7 @@ In addition to all arguments above, it also exports the following attributes:
### Stream Connection

* `project_id` - Unique 24-hexadecimal digit string that identifies your project.
* `instance_name` - Human-readable label that identifies the stream instance.
* `workspace_name` - Human-readable label that identifies the stream instance.
* `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. `AWSLambda`, `Cluster`, `Https`, `Kafka` or `Sample`.

Expand Down
21 changes: 12 additions & 9 deletions docs/resources/stream_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ subcategory: "Streams"
```terraform
resource "mongodbatlas_stream_connection" "test" {
project_id = var.project_id
instance_name = "InstanceName"
workspace_name = "WorkspaceName"
connection_name = "ConnectionName"
type = "Cluster"
cluster_name = "Cluster0"
Expand All @@ -31,7 +31,7 @@ resource "mongodbatlas_stream_connection" "test" {
```terraform
resource "mongodbatlas_stream_connection" "test" {
project_id = var.project_id
instance_name = "InstanceName"
workspace_name = "WorskpaceName"
connection_name = "ConnectionName"
type = "Cluster"
cluster_name = "OtherCluster"
Expand All @@ -44,7 +44,7 @@ resource "mongodbatlas_stream_connection" "test" {
```terraform
resource "mongodbatlas_stream_connection" "test" {
project_id = var.project_id
instance_name = "NewInstance"
workspace_name = "NewWorkspace"
connection_name = "KafkaConnection"
type = "Kafka"
authentication = {
Expand All @@ -67,7 +67,7 @@ resource "mongodbatlas_stream_connection" "test" {
```terraform
resource "mongodbatlas_stream_connection" "example-kafka-oauthbearer" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "KafkaOAuthbearerConnection"
type = "Kafka"
authentication = {
Expand Down Expand Up @@ -99,7 +99,7 @@ resource "mongodbatlas_stream_connection" "example-kafka-oauthbearer" {
```terraform
resource "mongodbatlas_stream_connection" "test" {
project_id = var.project_id
instance_name = "NewInstance"
workspace_name = "NewWorkspace"
connection_name = "KafkaConnection"
type = "Kafka"
authentication = {
Expand All @@ -123,7 +123,7 @@ resource "mongodbatlas_stream_connection" "test" {
```terraform
resource "mongodbatlas_stream_connection" "test" {
project_id = var.project_id
instance_name = "NewInstance"
workspace_name = "NewWorkspace"
connection_name = "AWSLambdaConnection"
type = "AWSLambda"
aws = {
Expand All @@ -138,7 +138,7 @@ resource "mongodbatlas_stream_connection" "test" {
```terraform
resource "mongodbatlas_stream_connection" "example-https" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "https_connection_tf_new"
type = "Https"
url = "https://example.com"
Expand All @@ -152,10 +152,13 @@ resource "mongodbatlas_stream_connection" "example-https" {
## Argument Reference

* `project_id` - (Required) Unique 24-hexadecimal digit string that identifies your project.
* `instance_name` - (Required) Human-readable label that identifies the stream instance.
* `instance_name` - (Deprecated) Human-readable label that identifies the stream instance. Attribute is deprecated and will be removed in version 3.0.0 in favor of `workspace_name`.
* `workspace_name` - (Optional) Human-readable label that identifies the stream instance. Conflicts with `instance_name`.
* `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 `AWSLambda`, `Cluster`, `Https`, `Kafka` or `Sample`.

~> **NOTE:** Either `instance_name` or `workspace_name` must be provided, but not both. These fields are functionally identical and `workspace_name` is an alias for `instance_name`. `workspace_name` should be used instead of `instance_name`.

If `type` is of value `Cluster` the following additional arguments are defined:
* `cluster_name` - Name of the cluster configured for this connection.
* `db_role_to_execute` - The name of a Built in or Custom DB Role to connect to an Atlas Cluster. See [DBRoleToExecute](#DBRoleToExecute).
Expand Down Expand Up @@ -209,7 +212,7 @@ If `type` is of value `Https` the following additional attributes are defined:

## Import

You can import a stream connection resource using the instance name, project ID, and connection name. The format must be `INSTANCE_NAME-PROJECT_ID-CONNECTION_NAME`. For example:
You can import a stream connection resource using the workspace name, project ID, and connection name. The format must be `WORKSPACE_NAME-PROJECT_ID-CONNECTION_NAME`. For example:

```
$ terraform import mongodbatlas_stream_connection.test "DefaultInstance-12251446ae5f3f6ec7968b13-NewConnection"
Expand Down
22 changes: 11 additions & 11 deletions examples/mongodbatlas_stream_connection/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "mongodbatlas_stream_instance" "example" {

resource "mongodbatlas_stream_connection" "example-cluster" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "ClusterConnection"
type = "Cluster"
cluster_name = var.cluster_name
Expand All @@ -21,7 +21,7 @@ resource "mongodbatlas_stream_connection" "example-cluster" {

resource "mongodbatlas_stream_connection" "example-cross-project-cluster" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "ClusterCrossProjectConnection"
type = "Cluster"
cluster_name = var.other_cluster
Expand All @@ -34,7 +34,7 @@ resource "mongodbatlas_stream_connection" "example-cross-project-cluster" {

resource "mongodbatlas_stream_connection" "example-kafka-plaintext" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "KafkaPlaintextConnection"
type = "Kafka"
authentication = {
Expand All @@ -58,7 +58,7 @@ resource "mongodbatlas_stream_connection" "example-kafka-plaintext" {

resource "mongodbatlas_stream_connection" "example-kafka-oauthbearer" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "KafkaOAuthbearerConnection"
type = "Kafka"
authentication = {
Expand Down Expand Up @@ -86,7 +86,7 @@ resource "mongodbatlas_stream_connection" "example-kafka-oauthbearer" {

resource "mongodbatlas_stream_connection" "example-kafka-ssl" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "KafkaSSLConnection"
type = "Kafka"
authentication = {
Expand All @@ -106,14 +106,14 @@ 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
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "sample_stream_solar"
type = "Sample"
}

resource "mongodbatlas_stream_connection" "example-aws-lambda" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "AWSLambdaConnection"
type = "AWSLambda"
aws = {
Expand All @@ -123,7 +123,7 @@ resource "mongodbatlas_stream_connection" "example-aws-lambda" {

resource "mongodbatlas_stream_connection" "example-https" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = "HttpsConnection"
type = "Https"
url = "https://example.com"
Expand All @@ -135,13 +135,13 @@ resource "mongodbatlas_stream_connection" "example-https" {

data "mongodbatlas_stream_connection" "example-kafka-ssl" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
workspace_name = mongodbatlas_stream_instance.example.instance_name
connection_name = mongodbatlas_stream_connection.example-kafka-ssl.connection_name
}

data "mongodbatlas_stream_connections" "example" {
project_id = var.project_id
instance_name = mongodbatlas_stream_instance.example.instance_name
project_id = var.project_id
workspace_name = mongodbatlas_stream_instance.example.instance_name
}

# example making use of data sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package streamconnection
import (
"context"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
dsschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
)
Expand All @@ -25,7 +29,27 @@ type streamConnectionDS struct {

func (d *streamConnectionDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = conversion.DataSourceSchemaFromResource(ResourceSchema(ctx), &conversion.DataSourceSchemaRequest{
RequiredFields: []string{"project_id", "instance_name", "connection_name"},
RequiredFields: []string{"project_id", "connection_name"},
OverridenFields: map[string]dsschema.Attribute{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we mean here with overridden?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unnecessary. I removed it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looks like we still need this so that terraform can use the workspace_name field in place of the instance name field. Without this we get errors due to terraform thinking that the datasource is being modified due to the mapping of the instance_name and workspace_name fields

"instance_name": dsschema.StringAttribute{
Optional: true,
MarkdownDescription: "Human-readable label that identifies the stream instance. Conflicts with `workspace_name`.",
Validators: []validator.String{
stringvalidator.ConflictsWith(path.Expressions{
path.MatchRelative().AtParent().AtName("workspace_name"),
}...),
},
},
"workspace_name": dsschema.StringAttribute{
Optional: true,
MarkdownDescription: "Human-readable label that identifies the stream instance. This is an alias for `instance_name`. Conflicts with `instance_name`.",
Validators: []validator.String{
stringvalidator.ConflictsWith(path.Expressions{
path.MatchRelative().AtParent().AtName("instance_name"),
}...),
},
},
},
})
}

Expand All @@ -38,15 +62,21 @@ func (d *streamConnectionDS) Read(ctx context.Context, req datasource.ReadReques

connV2 := d.Client.AtlasV2
projectID := streamConnectionConfig.ProjectID.ValueString()
instanceName := streamConnectionConfig.InstanceName.ValueString()
effectiveWorkspaceName := getEffectiveWorkspaceName(&streamConnectionConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this now fail if they pass instanceSize only?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check below will error if workspace_name and instance_name are both undefined. If both are defined, then there will also be an error in NewTFStreamConnectionWithInstanceName

So one of workspace_name and instance_name is essentially required

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, so for whoever continues to use instance_name there will be no impact, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that's correct!

if effectiveWorkspaceName == "" {
resp.Diagnostics.AddError("validation error", "workspace_name must be provided")
return
}
connectionName := streamConnectionConfig.ConnectionName.ValueString()
apiResp, _, err := connV2.StreamsApi.GetStreamConnection(ctx, projectID, instanceName, connectionName).Execute()
apiResp, _, err := connV2.StreamsApi.GetStreamConnection(ctx, projectID, effectiveWorkspaceName, connectionName).Execute()
if err != nil {
resp.Diagnostics.AddError("error fetching resource", err.Error())
return
}

newStreamConnectionModel, diags := NewTFStreamConnection(ctx, projectID, instanceName, nil, apiResp)
instanceName := streamConnectionConfig.InstanceName.ValueString()
workspaceName := streamConnectionConfig.WorkspaceName.ValueString()
newStreamConnectionModel, diags := NewTFStreamConnectionWithInstanceName(ctx, projectID, instanceName, workspaceName, nil, apiResp)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
return
Expand Down
Loading
Loading