Skip to content

Commit

Permalink
feat: update code to set environment ID in context
Browse files Browse the repository at this point in the history
  • Loading branch information
Gezi-lzq committed Aug 19, 2024
1 parent 23acace commit 70540f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/provider/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ func (r *KafkaInstanceResource) Read(ctx context.Context, req resource.ReadReque
if resp.Diagnostics.HasError() {
return
}
if !state.EnvironmentID.IsNull() {
ctx = context.WithValue(ctx, client.EnvIdKey, state.EnvironmentID.ValueString())
}

instanceId := state.InstanceID.ValueString()
instance, err := r.client.GetKafkaInstance(ctx, instanceId)
Expand Down Expand Up @@ -313,6 +316,9 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
if resp.Diagnostics.HasError() {
return
}
if !state.EnvironmentID.IsNull() {
ctx = context.WithValue(ctx, client.EnvIdKey, state.EnvironmentID.ValueString())
}

// check if the instance exists
instanceId := plan.InstanceID.ValueString()
Expand Down Expand Up @@ -505,10 +511,13 @@ func (r *KafkaInstanceResource) Delete(ctx context.Context, req resource.DeleteR

// Read Terraform prior state data into the model
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)

if resp.Diagnostics.HasError() {
return
}
if !state.EnvironmentID.IsNull() {
ctx = context.WithValue(ctx, client.EnvIdKey, state.EnvironmentID.ValueString())
}

instanceId := state.InstanceID.ValueString()
instance, err := r.client.GetKafkaInstance(ctx, instanceId)
if err != nil {
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 @@ -166,6 +166,9 @@ func (r *KafkaTopicResource) Update(ctx context.Context, req resource.UpdateRequ
if resp.Diagnostics.HasError() {
return
}
if !state.EnvironmentID.IsNull() {
ctx = context.WithValue(ctx, client.EnvIdKey, state.EnvironmentID.ValueString())
}

instanceId := plan.KafkaInstance.ValueString()
topicId := plan.TopicID.ValueString()
Expand Down Expand Up @@ -231,6 +234,9 @@ func (r *KafkaTopicResource) Delete(ctx context.Context, req resource.DeleteRequ
if resp.Diagnostics.HasError() {
return
}
if !state.EnvironmentID.IsNull() {
ctx = context.WithValue(ctx, client.EnvIdKey, state.EnvironmentID.ValueString())
}

topicId := state.TopicID.ValueString()
instanceId := state.KafkaInstance.ValueString()
Expand Down

0 comments on commit 70540f4

Please sign in to comment.