Skip to content

Commit

Permalink
Audit error reporting (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
erademacher committed Nov 17, 2022
1 parent d57f5f9 commit 91fddff
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
14 changes: 6 additions & 8 deletions internal/provider/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (r clusterResource) Create(ctx context.Context, req tfsdk.CreateResourceReq
(plan.ServerlessConfig != nil && plan.DedicatedConfig != nil) {
resp.Diagnostics.AddError(
"Invalid cluster configuration",
"You must set either 'dedicated' or 'serverless', but not both.",
"You must set either 'dedicated' or 'serverless', but not both",
)
}

Expand Down Expand Up @@ -254,7 +254,7 @@ func (r clusterResource) Create(ctx context.Context, req tfsdk.CreateResourceReq
} else {
resp.Diagnostics.AddError(
"Invalid dedicated cluster configuration",
"A dedicated cluster needs either num_virtual_cpus or machine_type to be set.",
"A dedicated cluster needs either num_virtual_cpus or machine_type to be set",
)
}
hardware.MachineSpec = machineSpec
Expand Down Expand Up @@ -288,8 +288,8 @@ func (r clusterResource) Create(ctx context.Context, req tfsdk.CreateResourceReq
waitForClusterCreatedFunc(ctx, clusterObj.Id, r.provider.service, clusterObj))
if err != nil {
resp.Diagnostics.AddError(
"cluster ready timeout",
fmt.Sprintf("cluster is not ready: %s", formatAPIErrorMessage(err)),
"Cluster creation failed",
fmt.Sprintf("Cluster is not ready: %s", formatAPIErrorMessage(err)),
)
return
}
Expand Down Expand Up @@ -425,8 +425,8 @@ func (r clusterResource) Update(ctx context.Context, req tfsdk.UpdateResourceReq
waitForClusterCreatedFunc(ctx, clusterObj.Id, r.provider.service, clusterObj))
if err != nil {
resp.Diagnostics.AddError(
"cluster ready timeout",
fmt.Sprintf("cluster is not ready: %v %v "+err.Error()),
"Cluster update failed",
fmt.Sprintf("Cluster is not ready: %v %v "+err.Error()),
)
return
}
Expand All @@ -445,7 +445,6 @@ func (r clusterResource) Delete(ctx context.Context, req tfsdk.DeleteResourceReq
diags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
resp.Diagnostics.AddWarning("this is error loading cluster ", "")
return
}

Expand All @@ -455,7 +454,6 @@ func (r clusterResource) Delete(ctx context.Context, req tfsdk.DeleteResourceReq
}
clusterID := state.ID.Value

// Delete order by calling API
_, httpResp, err := r.provider.service.DeleteCluster(ctx, clusterID)
if err != nil {
if httpResp.StatusCode == http.StatusNotFound {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/cockroach_cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func (d clusterDataSource) Read(ctx context.Context, req tfsdk.ReadDataSourceReq
}
if err != nil {
resp.Diagnostics.AddError(
"error in getting cluster",
"")
"Error getting cluster info",
fmt.Sprintf("Unexpected error while retrieving cluster info: %v", formatAPIErrorMessage(err)))
}

cluster.Name = types.String{Value: cockroachCluster.Name}
Expand Down
20 changes: 6 additions & 14 deletions internal/provider/networking_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func (n allowListResource) Create(ctx context.Context, req tfsdk.CreateResourceR

if cluster.Config.Serverless != nil {
resp.Diagnostics.AddError(
"Could not add network allow list in serverless cluster",
fmt.Sprintf("Network allow list is a feature of dedicated cluster: %s", formatAPIErrorMessage(err)),
"Could not add network allowlist in serverless cluster",
"Network allowlists are only supported with dedicated clusters",
)
return
}
Expand Down Expand Up @@ -221,14 +221,6 @@ func (n allowListResource) Update(ctx context.Context, req tfsdk.UpdateResourceR
return
}

if state.ClusterId != plan.ClusterId {
resp.Diagnostics.AddError(
"can not change cluster id in the network allow list",
"You can only change network allow list. Thanks!",
)
return
}

clusterId := plan.ClusterId.Value
entryCIDRIp := plan.CidrIp.Value
entryCIDRMask := int32(plan.CidrMask.Value)
Expand All @@ -243,8 +235,8 @@ func (n allowListResource) Update(ctx context.Context, req tfsdk.UpdateResourceR
&existingAllowList, &client.UpdateAllowlistEntryOptions{})
if err != nil {
resp.Diagnostics.AddError(
"Error updating network allow list",
fmt.Sprintf("Could not update network allow list: %s", formatAPIErrorMessage(err)),
"Error updating network allowlist",
fmt.Sprintf("Could not update network allowlist: %s", formatAPIErrorMessage(err)),
)
return
}
Expand All @@ -267,8 +259,8 @@ func (n allowListResource) Delete(ctx context.Context, req tfsdk.DeleteResourceR
_, _, err := n.provider.service.DeleteAllowlistEntry(ctx, state.ClusterId.Value, state.CidrIp.Value, int32(state.CidrMask.Value))
if err != nil {
resp.Diagnostics.AddError(
"Error deleting network allow list",
fmt.Sprintf("Could not delete network allow list: %s", formatAPIErrorMessage(err)),
"Error deleting network allowlist",
fmt.Sprintf("Could not delete network allowlist: %s", formatAPIErrorMessage(err)),
)
return
}
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/private_endpoint_connection_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ func (r privateEndpointConnectionResource) Create(ctx context.Context, req tfsdk
if cluster.Config.Serverless != nil {
resp.Diagnostics.AddError(
"Incompatible cluster type",
"Private endpoint services are only available for dedicated clusters.",
"Private endpoint services are only available for dedicated clusters",
)
return
} else if cluster.CloudProvider != client.APICLOUDPROVIDER_AWS {
resp.Diagnostics.AddError(
"Incompatible cluster cloud provider",
"Private endpoint services are only available for AWS clusters.",
"Private endpoint services are only available for AWS clusters",
)
return
}
Expand Down Expand Up @@ -164,8 +164,8 @@ func (r privateEndpointConnectionResource) Create(ctx context.Context, req tfsdk
waitForEndpointConnectionCreatedFunc(ctx, cluster.Id, plan.EndpointID.Value, r.provider.service, &connection))
if err != nil {
resp.Diagnostics.AddError(
"Error enabling private endpoint services",
fmt.Sprintf("Could not enable private endpoint services: %s", formatAPIErrorMessage(err)),
"Error accepting private endpoint connection",
fmt.Sprintf("Could not accept private endpoint connection: %s", formatAPIErrorMessage(err)),
)
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/private_endpoint_services_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ func (n privateEndpointServicesResource) Create(ctx context.Context, req tfsdk.C
if cluster.Config.Serverless != nil {
resp.Diagnostics.AddError(
"Incompatible cluster type",
"Private endpoint services are only available for dedicated clusters.",
"Private endpoint services are only available for dedicated clusters",
)
return
} else if cluster.CloudProvider != client.APICLOUDPROVIDER_AWS {
resp.Diagnostics.AddError(
"Incompatible cluster cloud provider",
"Private endpoint services are only available for AWS clusters.",
"Private endpoint services are currently only available for AWS clusters",
)
return
}
Expand Down

0 comments on commit 91fddff

Please sign in to comment.