Skip to content

Commit

Permalink
fix: supplement missing errors and exit processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gezi-lzq committed Aug 21, 2024
1 parent ff10428 commit 1dd0b49
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/provider/datasource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (r *KafkaInstanceDataSource) Read(ctx context.Context, req datasource.ReadR
return
}
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get Kafka instance %q, got error: %s", instanceId, err))
return
}
if out == nil {
resp.Diagnostics.AddError(fmt.Sprintf("Kafka instance %q not found", instanceId), err.Error())
Expand Down
20 changes: 20 additions & 0 deletions internal/provider/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func (r *KafkaInstanceResource) Read(ctx context.Context, req resource.ReadReque
return
}
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get Kafka instance %q, got error: %s", state.InstanceID.ValueString(), err))
return
}
// Get instance integrations
integrations, err := r.client.ListInstanceIntegrations(ctx, instanceId)
Expand Down Expand Up @@ -354,6 +355,9 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
}
// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
}
// Check if the ACL has changed
if state.ACL.ValueBool() != plan.ACL.ValueBool() {
Expand All @@ -375,6 +379,9 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
}
// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
}

// Check if the Integrations has changed
Expand Down Expand Up @@ -409,6 +416,9 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
}
// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
}

updateTimeout := r.UpdateTimeout(ctx, state.Timeouts)
Expand All @@ -434,6 +444,7 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
_, err := r.client.UpdateKafkaInstanceConfig(ctx, instanceId, in)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update Kafka instance %q, got error: %s", instanceId, err))
return
}

// wait for version update
Expand All @@ -447,6 +458,9 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
return
}
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
}

// Check if the compute specs (version) has changed
Expand All @@ -470,6 +484,9 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
}
// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
}

stateAKU := state.ComputeSpecs.Aku.ValueInt64()
Expand Down Expand Up @@ -500,6 +517,9 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
}
// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/provider/resource_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (r *KafkaTopicResource) Create(ctx context.Context, req resource.CreateRequ
out, err := r.client.CreateKafkaTopic(ctx, instanceId, in)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create Kafka topic %q, got error: %s", topic.Name.ValueString(), err))
return
}

resp.Diagnostics.Append(models.FlattenKafkaTopic(out, &topic)...)
Expand Down Expand Up @@ -144,9 +145,11 @@ func (r *KafkaTopicResource) Read(ctx context.Context, req resource.ReadRequest,
return
}
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get Kafka topic %q, got error: %s", topicId, err))
return
}
if out == nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get Kafka topic %q, got nil response", topicId))
return
}

resp.Diagnostics.Append(models.FlattenKafkaTopic(out, &data)...)
Expand Down Expand Up @@ -182,6 +185,7 @@ func (r *KafkaTopicResource) Update(ctx context.Context, req resource.UpdateRequ
err := r.client.UpdateKafkaTopicPartition(ctx, instanceId, topicId, in)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update Kafka topic %q, got error: %s", topicId, err))
return
}

resp.Diagnostics.Append(ReadKafkaTopic(ctx, r, instanceId, topicId, &plan)...)
Expand Down Expand Up @@ -212,6 +216,7 @@ func (r *KafkaTopicResource) Update(ctx context.Context, req resource.UpdateRequ
_, err := r.client.UpdateKafkaTopicConfig(ctx, instanceId, topicId, in)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update Kafka topic %q, got error: %s", topicId, err))
return
}

resp.Diagnostics.Append(ReadKafkaTopic(ctx, r, instanceId, topicId, &plan)...)
Expand All @@ -238,6 +243,7 @@ func (r *KafkaTopicResource) Delete(ctx context.Context, req resource.DeleteRequ
err := r.client.DeleteKafkaTopic(ctx, instanceId, topicId)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete Kafka topic %q, got error: %s", topicId, err))
return
}
}

Expand Down

0 comments on commit 1dd0b49

Please sign in to comment.