-
Notifications
You must be signed in to change notification settings - Fork 208
feat: Add workspace_name field in stream_connection resource and datasource #3610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
31304ee
4d06c1e
4530ef5
bdeb3ef
096bc32
d04b471
4254b34
77e7b9e
f5f3d27
0ff807b
7b9bd5a
65d04b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
kpatel71716 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` | ||
|
||
```release-note:enhancement | ||
data-source/mongodbatlas_stream_connections: Adds support for GCP as a Cloud Provider. | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
@@ -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{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do we mean here with overridden? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was unnecessary. I removed it There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"), | ||
}...), | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
|
@@ -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) | ||
kpatel71716 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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 | ||
|
Uh oh!
There was an error while loading. Please reload this page.