@@ -123,12 +123,16 @@ func NewStreamConnectionUpdateReq(ctx context.Context, plan *TFStreamConnectionM
123
123
return streamConnection , nil
124
124
}
125
125
126
- func NewTFStreamConnection (ctx context.Context , projID , instanceName string , currAuthConfig * types.Object , apiResp * admin.StreamsConnection ) (* TFStreamConnectionModel , diag.Diagnostics ) {
126
+ func NewTFStreamConnection (ctx context.Context , projID , workspaceName string , currAuthConfig * types.Object , apiResp * admin.StreamsConnection ) (* TFStreamConnectionModel , diag.Diagnostics ) {
127
+ return NewTFStreamConnectionWithInstanceName (ctx , projID , "" , workspaceName , currAuthConfig , apiResp )
128
+ }
129
+
130
+ // determines if the original model was created with instance_name or workspace_name and sets the appropriate field
131
+ func NewTFStreamConnectionWithInstanceName (ctx context.Context , projID , instanceName string , workspaceName string , currAuthConfig * types.Object , apiResp * admin.StreamsConnection ) (* TFStreamConnectionModel , diag.Diagnostics ) {
127
132
rID := fmt .Sprintf ("%s-%s-%s" , instanceName , projID , conversion .SafeString (apiResp .Name ))
128
133
connectionModel := TFStreamConnectionModel {
129
134
ID : types .StringValue (rID ),
130
135
ProjectID : types .StringValue (projID ),
131
- InstanceName : types .StringValue (instanceName ),
132
136
ConnectionName : types .StringPointerValue (apiResp .Name ),
133
137
Type : types .StringPointerValue (apiResp .Type ),
134
138
ClusterName : types .StringPointerValue (apiResp .ClusterName ),
@@ -137,6 +141,19 @@ func NewTFStreamConnection(ctx context.Context, projID, instanceName string, cur
137
141
URL : types .StringPointerValue (apiResp .Url ),
138
142
}
139
143
144
+ if workspaceName != "" && instanceName != "" {
145
+ return nil , diag.Diagnostics {diag .NewErrorDiagnostic ("Attribute \" instance_name\" cannot be specified when \" workspace_name\" is specified" , "" )}
146
+ }
147
+ // Set the appropriate field based on the original model
148
+ if workspaceName != "" {
149
+ connectionModel .WorkspaceName = types .StringValue (workspaceName )
150
+ connectionModel .InstanceName = types .StringNull ()
151
+ } else {
152
+ // Default to instance_name for backward compatibility
153
+ connectionModel .InstanceName = types .StringValue (instanceName )
154
+ connectionModel .WorkspaceName = types .StringNull ()
155
+ }
156
+
140
157
authModel , diags := newTFConnectionAuthenticationModel (ctx , currAuthConfig , apiResp .Authentication )
141
158
if diags .HasError () {
142
159
return nil , diags
@@ -254,22 +271,30 @@ func NewTFStreamConnections(ctx context.Context,
254
271
paginatedResult * admin.PaginatedApiStreamsConnection ) (* TFStreamConnectionsDSModel , diag.Diagnostics ) {
255
272
input := paginatedResult .GetResults ()
256
273
results := make ([]TFStreamConnectionModel , len (input ))
274
+
275
+ workspaceName := streamConnectionsConfig .WorkspaceName .ValueString ()
276
+ instanceName := streamConnectionsConfig .InstanceName .ValueString ()
277
+ if workspaceName != "" && instanceName != "" {
278
+ return nil , diag.Diagnostics {diag .NewErrorDiagnostic ("Attribute \" instance_name\" cannot be specified when \" workspace_name\" is specified" , "" )}
279
+ }
280
+
257
281
for i := range input {
258
282
projectID := streamConnectionsConfig .ProjectID .ValueString ()
259
- instanceName := streamConnectionsConfig .InstanceName .ValueString ()
260
- connectionModel , diags := NewTFStreamConnection (ctx , projectID , instanceName , nil , & input [i ])
283
+ connectionModel , diags := NewTFStreamConnectionWithInstanceName (ctx , projectID , instanceName , workspaceName , nil , & input [i ])
261
284
if diags .HasError () {
262
285
return nil , diags
263
286
}
264
287
results [i ] = * connectionModel
265
288
}
289
+
266
290
return & TFStreamConnectionsDSModel {
267
- ID : types .StringValue (id .UniqueId ()),
268
- ProjectID : streamConnectionsConfig .ProjectID ,
269
- InstanceName : streamConnectionsConfig .InstanceName ,
270
- Results : results ,
271
- PageNum : streamConnectionsConfig .PageNum ,
272
- ItemsPerPage : streamConnectionsConfig .ItemsPerPage ,
273
- TotalCount : types .Int64PointerValue (conversion .IntPtrToInt64Ptr (paginatedResult .TotalCount )),
291
+ ID : types .StringValue (id .UniqueId ()),
292
+ ProjectID : streamConnectionsConfig .ProjectID ,
293
+ InstanceName : streamConnectionsConfig .InstanceName ,
294
+ WorkspaceName : streamConnectionsConfig .WorkspaceName ,
295
+ Results : results ,
296
+ PageNum : streamConnectionsConfig .PageNum ,
297
+ ItemsPerPage : streamConnectionsConfig .ItemsPerPage ,
298
+ TotalCount : types .Int64PointerValue (conversion .IntPtrToInt64Ptr (paginatedResult .TotalCount )),
274
299
}, nil
275
300
}
0 commit comments