diff --git a/internal/provider/datasource_instance.go b/internal/provider/datasource_instance.go index 549c20b..b4faffc 100644 --- a/internal/provider/datasource_instance.go +++ b/internal/provider/datasource_instance.go @@ -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()) diff --git a/internal/provider/resource_instance.go b/internal/provider/resource_instance.go index 3a5b013..eb1d6c1 100644 --- a/internal/provider/resource_instance.go +++ b/internal/provider/resource_instance.go @@ -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) @@ -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() { @@ -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 @@ -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) @@ -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 @@ -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 @@ -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() @@ -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 + } } } diff --git a/internal/provider/resource_topic.go b/internal/provider/resource_topic.go index 1208451..dc60a95 100644 --- a/internal/provider/resource_topic.go +++ b/internal/provider/resource_topic.go @@ -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)...) @@ -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)...) @@ -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)...) @@ -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)...) @@ -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 } }