Skip to content

Commit 4f31776

Browse files
authored
fix import of streaming tenants (#445)
fix import when there are multiple streaming tenants with the same name fixes: #256
1 parent 3a06b1d commit 4f31776

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

docs/resources/streaming_tenant.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ output "web_socket_url" {
7979
- `cluster_name` (String) Pulsar cluster name. Required if `cloud_provider` and `region` are not specified.
8080
- `deletion_protection` (Boolean) Whether or not to allow Terraform to destroy this tenant. Unless this field is set to false in Terraform state, a `terraform destroy` or `terraform apply` command that deletes the instance will fail. Defaults to `true`.
8181
- `region` (String, Deprecated) Cloud provider region. Required if `cluster_name` is not set.
82-
- `topic` (String, Deprecated) Streaming tenant topic. Please use the `astra_streaming_topic` resource instead.
82+
- `topic` (String, Deprecated) Streaming tenant topic. Use the `astra_streaming_topic` resource instead.
8383

8484
### Read-Only
8585

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22.7
55
toolchain go1.24.2
66

77
require (
8-
github.com/datastax/astra-client-go/v2 v2.2.61
8+
github.com/datastax/astra-client-go/v2 v2.2.62
99
github.com/datastax/pulsar-admin-client-go v0.0.2
1010
github.com/google/uuid v1.6.0
1111
github.com/hashicorp/go-cty v1.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
105105
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
106106
github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo=
107107
github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
108-
github.com/datastax/astra-client-go/v2 v2.2.61 h1:yT8pn8aUsBhte7VYv4o7Pc0TeyXrCppg3q+HjV3+tUA=
109-
github.com/datastax/astra-client-go/v2 v2.2.61/go.mod h1:piBMy3fnDcLN8+MDQfvjZr8ejcP2oh+CXkQYwNy8blA=
108+
github.com/datastax/astra-client-go/v2 v2.2.62 h1:HpOxYgZ7ng9ASz0R0MYh1du2VkWt6R5GM0xof83j4p0=
109+
github.com/datastax/astra-client-go/v2 v2.2.62/go.mod h1:piBMy3fnDcLN8+MDQfvjZr8ejcP2oh+CXkQYwNy8blA=
110110
github.com/datastax/pulsar-admin-client-go v0.0.2 h1:CValQbSLI6q1PuCzkM4Tr3tAgwSi6RYDJ7PxvcBLyhw=
111111
github.com/datastax/pulsar-admin-client-go v0.0.2/go.mod h1:GOBpX6jwznrSlECwGeOZE6sNFJJ+FtYkwlv8PgFCZng=
112112
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

internal/provider/resource_streaming_tenant.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (r *StreamingTenantResource) Schema(_ context.Context, _ resource.SchemaReq
113113
Required: true,
114114
},
115115
"topic": schema.StringAttribute{
116-
Description: "Streaming tenant topic. Please use the `astra_streaming_topic` resource instead.",
116+
Description: "Streaming tenant topic. Use the `astra_streaming_topic` resource instead.",
117117
Optional: true,
118118
DeprecationMessage: "This field is deprecated and will be removed in a future release. Please use the `astra_streaming_topic` resource instead.",
119119
Validators: []validator.String{stringvalidator.RegexMatches(regexp.MustCompile("^.{2,}"),
@@ -226,11 +226,11 @@ func (r *StreamingTenantResource) Create(ctx context.Context, req resource.Creat
226226
UserEmail: plan.UserEmail.ValueStringPointer(),
227227
}
228228

229-
params := astrastreaming.IdOfCreateTenantEndpointParams{
229+
postParams := astrastreaming.IdOfCreateTenantEndpointParams{
230230
Topic: plan.Topic.ValueStringPointer(),
231231
}
232232

233-
tenantCreateResponse, err := astraStreamingClient.IdOfCreateTenantEndpointWithResponse(ctx, &params, tenantRequest)
233+
tenantCreateResponse, err := astraStreamingClient.IdOfCreateTenantEndpointWithResponse(ctx, &postParams, tenantRequest)
234234
if err != nil {
235235
resp.Diagnostics.AddError(
236236
"failed to create tenant",
@@ -243,8 +243,14 @@ func (r *StreamingTenantResource) Create(ctx context.Context, req resource.Creat
243243
return
244244
}
245245

246+
if plan.ClusterName.IsNull() || plan.ClusterName.IsUnknown() {
247+
plan.ClusterName = types.StringPointerValue(tenantCreateResponse.JSON200.ClusterName)
248+
}
249+
getParams := &astrastreaming.GetStreamingTenantParams{
250+
XDataStaxPulsarCluster: plan.ClusterName.ValueString(),
251+
}
246252
// Now fetch the tenant again so that it fills in the missing fields (like userMetricsUrl and tenant ID)
247-
tenantGetResponse, err := astraStreamingClient.GetStreamingTenantWithResponse(ctx, orgID, plan.TenantName.ValueString())
253+
tenantGetResponse, err := astraStreamingClient.GetStreamingTenantWithResponse(ctx, plan.TenantName.ValueString(), getParams)
248254
if err != nil {
249255
resp.Diagnostics.AddError("failed to get data for tenant "+plan.TenantName.ValueString(), err.Error())
250256
return
@@ -270,16 +276,12 @@ func (r *StreamingTenantResource) Read(ctx context.Context, req resource.ReadReq
270276
return
271277
}
272278

273-
astraClient := r.clients.astraClient
274279
astraStreamingClient := r.clients.astraStreamingClient
275280

276-
orgID, err := getCurrentOrgID(ctx, astraClient)
277-
if err != nil {
278-
resp.Diagnostics.AddError("failed to get tenant org ID", err.Error())
279-
return
281+
params := &astrastreaming.GetStreamingTenantParams{
282+
XDataStaxPulsarCluster: state.ClusterName.ValueString(),
280283
}
281-
282-
getTenantResponse, err := astraStreamingClient.GetStreamingTenantWithResponse(ctx, orgID, state.TenantName.ValueString())
284+
getTenantResponse, err := astraStreamingClient.GetStreamingTenantWithResponse(ctx, state.TenantName.ValueString(), params)
283285
if err != nil {
284286
resp.Diagnostics.AddError("failed to get tenant org ID", err.Error())
285287
return
@@ -317,6 +319,7 @@ func (r *StreamingTenantResource) Update(ctx context.Context, req resource.Updat
317319

318320
state.DeletionProtection = plan.DeletionProtection
319321
state.UserEmail = plan.UserEmail
322+
state.Topic = plan.Topic
320323
if !plan.Region.IsNull() && !plan.Region.IsUnknown() {
321324
state.Region = plan.Region
322325
}

0 commit comments

Comments
 (0)