Skip to content

Commit

Permalink
feat: update AutoMQ BYOC environment ID handling in resource_topic.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Gezi-lzq committed Aug 20, 2024
1 parent cbe9b80 commit 2435701
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
1 change: 0 additions & 1 deletion internal/provider/resource_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ provider "automq" {
automq_byoc_endpoint = "%s"
automq_byoc_access_key_id = "VLaUIeNYndeOAXjaol32o4UAHvX8A7VE"
automq_byoc_secret_key = "CHlRi0hOIA8pAnzW"
automq_environment_id = "env-1"
}
resource "automq_kafka_instance" "test" {
environment_id = "env-1"
Expand Down
18 changes: 5 additions & 13 deletions internal/provider/resource_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *KafkaTopicResource) Schema(ctx context.Context, req resource.SchemaRequ
Attributes: map[string]schema.Attribute{
"environment_id": schema.StringAttribute{
MarkdownDescription: "Target AutoMQ BYOC environment, this attribute is specified during the deployment and installation process.",
Optional: true,
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
},
"kafka_instance_id": schema.StringAttribute{
Expand Down Expand Up @@ -102,9 +102,7 @@ func (r *KafkaTopicResource) Create(ctx context.Context, req resource.CreateRequ
if resp.Diagnostics.HasError() {
return
}
if !topic.EnvironmentID.IsNull() {
ctx = context.WithValue(ctx, client.EnvIdKey, topic.EnvironmentID.ValueString())
}
ctx = context.WithValue(ctx, client.EnvIdKey, topic.EnvironmentID.ValueString())
// Generate API request body from plan
in := client.TopicCreateParam{}
models.ExpandKafkaTopicResource(topic, &in)
Expand Down Expand Up @@ -133,9 +131,7 @@ func (r *KafkaTopicResource) Read(ctx context.Context, req resource.ReadRequest,
if resp.Diagnostics.HasError() {
return
}
if !data.EnvironmentID.IsNull() {
ctx = context.WithValue(ctx, client.EnvIdKey, data.EnvironmentID.ValueString())
}
ctx = context.WithValue(ctx, client.EnvIdKey, data.EnvironmentID.ValueString())

topicId := data.TopicID.ValueString()
instanceId := data.KafkaInstance.ValueString()
Expand Down Expand Up @@ -166,9 +162,7 @@ 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())
}
ctx = context.WithValue(ctx, client.EnvIdKey, state.EnvironmentID.ValueString())

instanceId := plan.KafkaInstance.ValueString()
topicId := plan.TopicID.ValueString()
Expand Down Expand Up @@ -234,9 +228,7 @@ 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())
}
ctx = context.WithValue(ctx, client.EnvIdKey, state.EnvironmentID.ValueString())

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

0 comments on commit 2435701

Please sign in to comment.