Skip to content

Commit

Permalink
fix: update KafkaInstanceResourceModel in kafka_instance.go and repla…
Browse files Browse the repository at this point in the history
…ce "id" with "topic_id" (#27)

* feat: update KafkaInstanceResourceModel in kafka_instance.go

* feat: update ImportState function to use "topic_id" instead of "id" in KafkaTopicResource

* feat: update ComputeSpecsModel to use a pointer in kafka_instance_test.go
  • Loading branch information
Gezi-lzq authored Aug 16, 2024
1 parent 078deb9 commit 8bb0424
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
38 changes: 19 additions & 19 deletions internal/models/kafka_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ const (

// KafkaInstanceResourceModel describes the resource data model.
type KafkaInstanceResourceModel struct {
EnvironmentID types.String `tfsdk:"environment_id"`
InstanceID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
CloudProvider types.String `tfsdk:"cloud_provider"`
Region types.String `tfsdk:"region"`
Networks []NetworkModel `tfsdk:"networks"`
ComputeSpecs ComputeSpecsModel `tfsdk:"compute_specs"`
Configs types.Map `tfsdk:"configs"`
ACL types.Bool `tfsdk:"acl"`
Integrations types.List `tfsdk:"integrations"`
Endpoints types.List `tfsdk:"endpoints"`
CreatedAt timetypes.RFC3339 `tfsdk:"created_at"`
LastUpdated timetypes.RFC3339 `tfsdk:"last_updated"`
InstanceStatus types.String `tfsdk:"instance_status"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
EnvironmentID types.String `tfsdk:"environment_id"`
InstanceID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
CloudProvider types.String `tfsdk:"cloud_provider"`
Region types.String `tfsdk:"region"`
Networks []NetworkModel `tfsdk:"networks"`
ComputeSpecs *ComputeSpecsModel `tfsdk:"compute_specs"`
Configs types.Map `tfsdk:"configs"`
ACL types.Bool `tfsdk:"acl"`
Integrations types.List `tfsdk:"integrations"`
Endpoints types.List `tfsdk:"endpoints"`
CreatedAt timetypes.RFC3339 `tfsdk:"created_at"`
LastUpdated timetypes.RFC3339 `tfsdk:"last_updated"`
InstanceStatus types.String `tfsdk:"instance_status"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
}

type KafkaInstanceModel struct {
Expand Down Expand Up @@ -114,7 +114,7 @@ func ConvertKafkaInstanceModel(resource *KafkaInstanceResourceModel, model *Kafk
model.CloudProvider = resource.CloudProvider
model.Region = resource.Region
model.Networks = resource.Networks
model.ComputeSpecs = &resource.ComputeSpecs
model.ComputeSpecs = resource.ComputeSpecs
model.Configs = resource.Configs
model.ACL = resource.ACL
model.Integrations = resource.Integrations
Expand Down Expand Up @@ -202,15 +202,15 @@ func flattenNetworks(networks []client.Network) ([]NetworkModel, diag.Diagnostic
return networksModel, nil
}

func flattenComputeSpecs(spec client.Spec) ComputeSpecsModel {
func flattenComputeSpecs(spec client.Spec) *ComputeSpecsModel {
var aku types.Int64
for _, value := range spec.Values {
if value.Key == "aku" {
aku = types.Int64Value(int64(value.Value))
break
}
}
return ComputeSpecsModel{
return &ComputeSpecsModel{
Aku: aku,
Version: types.StringValue(spec.Version),
}
Expand Down
2 changes: 1 addition & 1 deletion internal/models/kafka_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestExpandKafkaInstanceResource(t *testing.T) {
Subnets: types.ListValueMust(types.StringType, []attr.Value{types.StringValue("subnet-1")}),
},
},
ComputeSpecs: ComputeSpecsModel{
ComputeSpecs: &ComputeSpecsModel{
Aku: types.Int64Value(4),
Version: types.StringValue("1.0.0"),
},
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (r *KafkaTopicResource) Delete(ctx context.Context, req resource.DeleteRequ
}

func (r *KafkaTopicResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
resource.ImportStatePassthroughID(ctx, path.Root("topic_id"), req, resp)
}

func ReadKafkaTopic(ctx context.Context, r *KafkaTopicResource, instanceId, topicId string, data *models.KafkaTopicResourceModel) diag.Diagnostics {
Expand Down

0 comments on commit 8bb0424

Please sign in to comment.