-
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
Changes from 20 commits
31304ee
4d06c1e
4530ef5
bdeb3ef
096bc32
d04b471
4254b34
77e7b9e
f5f3d27
0ff807b
7b9bd5a
65d04b1
088c340
9585758
6956236
4ab07bc
c9de513
f293a11
ce30a96
437b816
aef4ffe
38991cd
77badc2
6ac12af
4c667ae
4f89d24
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:note | ||
| resource/mongodbatlas_stream_connection: Deprecates the `instance_name` attribute. All configurations using `instance_name` should be updated to use the new `workspace_name` attribute instead | ||
|
|
||
| ``` | ||
| ```release-note:note | ||
| data-source/mongodbatlas_stream_connection: Deprecates the `instance_name` attribute. All configurations using `instance_name` should be updated to use the new `workspace_name` attribute instead | ||
| ``` | ||
|
|
||
| ```release-note:note | ||
| data-source/mongodbatlas_stream_connections: Deprecates the `instance_name` attribute. All configurations using `instance_name` should be updated to use the new `workspace_name` attribute instead | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,13 @@ import ( | |
| "context" | ||
| "fmt" | ||
|
|
||
| "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/hashicorp/terraform-plugin-framework/types" | ||
| "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" | ||
| "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" | ||
| "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" | ||
| "go.mongodb.org/atlas-sdk/v20250312007/admin" | ||
|
|
@@ -28,11 +33,39 @@ type streamConnectionsDS struct { | |
|
|
||
| func (d *streamConnectionsDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
| resp.Schema = conversion.PluralDataSourceSchemaFromResource(ResourceSchema(ctx), &conversion.PluralDataSourceSchemaRequest{ | ||
| RequiredFields: []string{"project_id", "instance_name"}, | ||
| RequiredFields: []string{"project_id"}, | ||
| HasLegacyFields: true, | ||
| OverridenRootFields: map[string]dsschema.Attribute{ | ||
| "instance_name": dsschema.StringAttribute{ | ||
| Optional: true, | ||
| MarkdownDescription: "Human-readable label that identifies the stream instance. Conflicts with `workspace_name`.", | ||
| DeprecationMessage: fmt.Sprintf(constant.DeprecationParamWithReplacement, "workspace_name"), | ||
| Validators: []validator.String{ | ||
| stringvalidator.ConflictsWith(path.MatchRoot("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.MatchRoot("instance_name")), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| // getWorkspaceOrInstanceNameForDS returns the workspace name from either instance_name or workspace_name field for datasource model | ||
| func getWorkspaceOrInstanceNameForDS(model *TFStreamConnectionsDSModel) string { | ||
| if !model.WorkspaceName.IsNull() && !model.WorkspaceName.IsUnknown() { | ||
| return model.WorkspaceName.ValueString() | ||
| } | ||
| if !model.InstanceName.IsNull() && !model.InstanceName.IsUnknown() { | ||
| return model.InstanceName.ValueString() | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func (d *streamConnectionsDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
| var streamConnectionsConfig TFStreamConnectionsDSModel | ||
| resp.Diagnostics.Append(req.Config.Get(ctx, &streamConnectionsConfig)...) | ||
|
|
@@ -42,13 +75,17 @@ func (d *streamConnectionsDS) Read(ctx context.Context, req datasource.ReadReque | |
|
|
||
| connV2 := d.Client.AtlasV2 | ||
| projectID := streamConnectionsConfig.ProjectID.ValueString() | ||
| instanceName := streamConnectionsConfig.InstanceName.ValueString() | ||
| workspaceOrInstanceName := getWorkspaceOrInstanceNameForDS(&streamConnectionsConfig) | ||
| if workspaceOrInstanceName == "" { | ||
| resp.Diagnostics.AddError("validation error", "workspace_name must be provided") | ||
| return | ||
| } | ||
| itemsPerPage := streamConnectionsConfig.ItemsPerPage.ValueInt64Pointer() | ||
| pageNum := streamConnectionsConfig.PageNum.ValueInt64Pointer() | ||
|
|
||
| apiResp, _, err := connV2.StreamsApi.ListStreamConnectionsWithParams(ctx, &admin.ListStreamConnectionsApiParams{ | ||
| GroupId: projectID, | ||
| TenantName: instanceName, | ||
| TenantName: workspaceOrInstanceName, | ||
| ItemsPerPage: conversion.Int64PtrToIntPtr(itemsPerPage), | ||
| PageNum: conversion.Int64PtrToIntPtr(pageNum), | ||
| }).Execute() | ||
|
|
@@ -67,11 +104,12 @@ func (d *streamConnectionsDS) Read(ctx context.Context, req datasource.ReadReque | |
| } | ||
|
|
||
| type TFStreamConnectionsDSModel struct { | ||
| ID types.String `tfsdk:"id"` | ||
| ProjectID types.String `tfsdk:"project_id"` | ||
| InstanceName types.String `tfsdk:"instance_name"` | ||
| Results []TFStreamConnectionModel `tfsdk:"results"` | ||
| PageNum types.Int64 `tfsdk:"page_num"` | ||
| ItemsPerPage types.Int64 `tfsdk:"items_per_page"` | ||
| TotalCount types.Int64 `tfsdk:"total_count"` | ||
| ID types.String `tfsdk:"id"` | ||
| ProjectID types.String `tfsdk:"project_id"` | ||
| InstanceName types.String `tfsdk:"instance_name"` | ||
| WorkspaceName types.String `tfsdk:"workspace_name"` | ||
| Results []TFStreamConnectionModel `tfsdk:"results"` | ||
| PageNum types.Int64 `tfsdk:"page_num"` | ||
| ItemsPerPage types.Int64 `tfsdk:"items_per_page"` | ||
|
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. not probably for this PR, but we're preferring not to expose pagination parameter and instead just return the whole list of items 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. that sgtm, I just took the existing pattern but will make a JIRA ticket for us to track cleaning this up |
||
| TotalCount types.Int64 `tfsdk:"total_count"` | ||
| } | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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