Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronblevy committed Jan 4, 2024
1 parent 43536c0 commit 91abd39
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion examples/resources/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ resource "timescale_service" "test" {
# milli_cpu = 1000
# memory_gb = 4
# region_code = ""

}

# Read replica
Expand Down
14 changes: 5 additions & 9 deletions internal/provider/service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
ErrCreateTimeout = "Error waiting for service creation"
ErrUpdateService = "Error updating service"
ErrInvalidAttribute = "Invalid Attribute Value"
ErrMultipleReadReplicas = "cannot create multiple read replicas for a service"
errMultipleReadReplicas = "cannot create multiple read replicas for a service"

DefaultMilliCPU = 500
DefaultMemoryGB = 2
Expand Down Expand Up @@ -90,6 +90,7 @@ func (r *ServiceResource) Schema(ctx context.Context, req resource.SchemaRequest
resp.Schema = schema.Schema{
// This description is used by the documentation generator and the language server.
MarkdownDescription: `A Service is a TimescaleDB instance.
Please note that when updating the vpc_id attribute, it is possible to encounter a "no Endpoint for that service id exists" error.
The change has been taken into account but must still be propagated. You can run "terraform refresh" shortly to get the updated data.`,
Attributes: map[string]schema.Attribute{
Expand All @@ -107,9 +108,6 @@ The change has been taken into account but must still be propagated. You can run
Optional: true,
// If the name attribute is absent, the provider will generate a default.
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"milli_cpu": schema.Int64Attribute{
MarkdownDescription: "Milli CPU",
Expand All @@ -135,7 +133,6 @@ The change has been taken into account but must still be propagated. You can run
MarkdownDescription: "If set, this database will be a read replica of the provided source database. The region must be the same as the source, or if ommitted will be handled by the provider",
Description: "If set, this database will be a read replica of the provided source database. The region must be the same as the source, or if ommitted will be handled by the provider",
Optional: true,
Validators: []validator.String{},
},
"storage_gb": schema.Int64Attribute{
MarkdownDescription: "Deprecated: Storage GB",
Expand Down Expand Up @@ -255,10 +252,10 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
// Locking is done to prevent multiple read replicas being created for a service at once
readReplicaMu.Lock()
defer readReplicaMu.Unlock()

primary, err := r.client.GetService(ctx, readReplicaSource)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get primary service %s, got error: %s", readReplicaSource, err))
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("unable to get primary service %s, got error: %s", readReplicaSource, err))
return
}
err = r.validateReadReplicaRequest(ctx, primary, plan)
Expand Down Expand Up @@ -297,7 +294,6 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
}
return
}

resourceModel := serviceToResource(resp.Diagnostics, service, plan)
resp.Diagnostics.Append(resp.State.Set(ctx, resourceModel)...)
if resp.Diagnostics.HasError() {
Expand All @@ -321,7 +317,7 @@ func (r *ServiceResource) validateReadReplicaRequest(ctx context.Context, primar
}
for _, service := range services {
if service.ForkedSpec != nil && service.ForkedSpec.ServiceID == primary.ID {
return errors.New(ErrMultipleReadReplicas)
return errors.New(errMultipleReadReplicas)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestServiceResource_Read_Replica(t *testing.T) {
Steps: []resource.TestStep{
{
Config: newServiceWithReadReplica(t, primaryConfig, replicaConfig) + secondReadReplica.String(t),
ExpectError: regexp.MustCompile(ErrMultipleReadReplicas),
ExpectError: regexp.MustCompile(errMultipleReadReplicas),
},
},
})
Expand Down

0 comments on commit 91abd39

Please sign in to comment.