ClickHouse / terraform-provider-clickhouse

Terraform Provider for ClickHouse Cloud
Apache License 2.0
20 stars 7 forks source link

Refactoring #111

Closed whites11 closed 1 month ago

whites11 commented 1 month ago

I created an explicit struct for all terraform Objects used in the service resource. This allows to avoid having hardcorded field names all over the place.

Example:

To create an Endpoint in the terraform state, instead of doing:

obj, _ := types.ObjectValue(endpointObjectType.AttrTypes, map[string]attr.Value{
            "protocol": types.StringValue(endpoint.Protocol),
            "host":     types.StringValue(endpoint.Host),
            "port":     types.Int64Value(int64(endpoint.Port)),
        })

now you can do

models.Endpoint{
  Protocol: types.StringValue(endpoint.Protocol),
  Host: types.StringValue(endpoint.Host),
  Port: types.Int64Value(int64(endpoint.Port))
}.ObjectValue()

and the field names are known by the models.Endpoint type only.

I also moved the terraform model definitions again (sorry)