Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion docs/resources/streaming_tenant.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ output "web_socket_url" {
- `cluster_name` (String) Pulsar cluster name. Required if `cloud_provider` and `region` are not specified.
- `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`.
- `region` (String, Deprecated) Cloud provider region. Required if `cluster_name` is not set.
- `topic` (String, Deprecated) Streaming tenant topic. Please use the `astra_streaming_topic` resource instead.
- `topic` (String, Deprecated) Streaming tenant topic. Use the `astra_streaming_topic` resource instead.

### Read-Only

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.7
toolchain go1.24.2

require (
github.com/datastax/astra-client-go/v2 v2.2.61
github.com/datastax/astra-client-go/v2 v2.2.62
github.com/datastax/pulsar-admin-client-go v0.0.2
github.com/google/uuid v1.6.0
github.com/hashicorp/go-cty v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo=
github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/datastax/astra-client-go/v2 v2.2.61 h1:yT8pn8aUsBhte7VYv4o7Pc0TeyXrCppg3q+HjV3+tUA=
github.com/datastax/astra-client-go/v2 v2.2.61/go.mod h1:piBMy3fnDcLN8+MDQfvjZr8ejcP2oh+CXkQYwNy8blA=
github.com/datastax/astra-client-go/v2 v2.2.62 h1:HpOxYgZ7ng9ASz0R0MYh1du2VkWt6R5GM0xof83j4p0=
github.com/datastax/astra-client-go/v2 v2.2.62/go.mod h1:piBMy3fnDcLN8+MDQfvjZr8ejcP2oh+CXkQYwNy8blA=
github.com/datastax/pulsar-admin-client-go v0.0.2 h1:CValQbSLI6q1PuCzkM4Tr3tAgwSi6RYDJ7PxvcBLyhw=
github.com/datastax/pulsar-admin-client-go v0.0.2/go.mod h1:GOBpX6jwznrSlECwGeOZE6sNFJJ+FtYkwlv8PgFCZng=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
25 changes: 14 additions & 11 deletions internal/provider/resource_streaming_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (r *StreamingTenantResource) Schema(_ context.Context, _ resource.SchemaReq
Required: true,
},
"topic": schema.StringAttribute{
Description: "Streaming tenant topic. Please use the `astra_streaming_topic` resource instead.",
Description: "Streaming tenant topic. Use the `astra_streaming_topic` resource instead.",
Optional: true,
DeprecationMessage: "This field is deprecated and will be removed in a future release. Please use the `astra_streaming_topic` resource instead.",
Validators: []validator.String{stringvalidator.RegexMatches(regexp.MustCompile("^.{2,}"),
Expand Down Expand Up @@ -226,11 +226,11 @@ func (r *StreamingTenantResource) Create(ctx context.Context, req resource.Creat
UserEmail: plan.UserEmail.ValueStringPointer(),
}

params := astrastreaming.IdOfCreateTenantEndpointParams{
postParams := astrastreaming.IdOfCreateTenantEndpointParams{
Topic: plan.Topic.ValueStringPointer(),
}

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

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

astraClient := r.clients.astraClient
astraStreamingClient := r.clients.astraStreamingClient

orgID, err := getCurrentOrgID(ctx, astraClient)
if err != nil {
resp.Diagnostics.AddError("failed to get tenant org ID", err.Error())
return
params := &astrastreaming.GetStreamingTenantParams{
XDataStaxPulsarCluster: state.ClusterName.ValueString(),
}

getTenantResponse, err := astraStreamingClient.GetStreamingTenantWithResponse(ctx, orgID, state.TenantName.ValueString())
getTenantResponse, err := astraStreamingClient.GetStreamingTenantWithResponse(ctx, state.TenantName.ValueString(), params)
if err != nil {
resp.Diagnostics.AddError("failed to get tenant org ID", err.Error())
return
Expand Down Expand Up @@ -317,6 +319,7 @@ func (r *StreamingTenantResource) Update(ctx context.Context, req resource.Updat

state.DeletionProtection = plan.DeletionProtection
state.UserEmail = plan.UserEmail
state.Topic = plan.Topic
if !plan.Region.IsNull() && !plan.Region.IsUnknown() {
state.Region = plan.Region
}
Expand Down
Loading