From 91abd39b1cc5b41c04ae85755c0a08f852f2a193 Mon Sep 17 00:00:00 2001 From: Aaron Levy Date: Thu, 4 Jan 2024 11:33:47 -0500 Subject: [PATCH] cleanups --- examples/resources/resource.tf | 1 - internal/provider/service_resource.go | 14 +++++--------- internal/provider/service_resource_test.go | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/examples/resources/resource.tf b/examples/resources/resource.tf index 5a689d1..2a5f8e4 100644 --- a/examples/resources/resource.tf +++ b/examples/resources/resource.tf @@ -3,7 +3,6 @@ resource "timescale_service" "test" { # milli_cpu = 1000 # memory_gb = 4 # region_code = "" - } # Read replica diff --git a/internal/provider/service_resource.go b/internal/provider/service_resource.go index c48d47c..4561532 100644 --- a/internal/provider/service_resource.go +++ b/internal/provider/service_resource.go @@ -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 @@ -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{ @@ -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", @@ -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", @@ -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) @@ -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() { @@ -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 diff --git a/internal/provider/service_resource_test.go b/internal/provider/service_resource_test.go index 8972db9..868eaec 100644 --- a/internal/provider/service_resource_test.go +++ b/internal/provider/service_resource_test.go @@ -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), }, }, })