Skip to content

Commit

Permalink
more fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Jan 30, 2025
1 parent 0549737 commit 335cb41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
5 changes: 0 additions & 5 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,3 @@ provider "ctrlplane" {
base_url = "http://localhost:3000"
workspace = "ctrlplane"
}

resource "ctrlplane_system" "example" {
name = "tf_test_official"
slug = "tf_test_official"
}
8 changes: 2 additions & 6 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,11 @@ func (p *CtrlplaneProvider) Resources(ctx context.Context) []func() resource.Res
}

func (p *CtrlplaneProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
NewExampleDataSource,
}
return []func() datasource.DataSource{}
}

func (p *CtrlplaneProvider) Functions(ctx context.Context) []func() function.Function {
return []func() function.Function{
NewExampleFunction,
}
return []func() function.Function{}
}

func New(version string) func() provider.Provider {
Expand Down
25 changes: 17 additions & 8 deletions internal/provider/system_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package provider
import (
"context"
"fmt"
"net/http"
"terraform-provider-ctrlplane/client"

"github.com/google/uuid"
Expand All @@ -22,8 +21,8 @@ func NewSystemResource() resource.Resource {
}

type systemResource struct {
client *client.ClientWithResponses
workspaceID uuid.UUID
client *client.ClientWithResponses
workspace uuid.UUID
}

func (r *systemResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
Expand All @@ -41,7 +40,7 @@ func (r *systemResource) Configure(_ context.Context, req resource.ConfigureRequ
}

r.client = dataSourceModel.Client
r.workspaceID = dataSourceModel.Workspace
r.workspace = dataSourceModel.Workspace
}

// Metadata returns the resource type name.
Expand Down Expand Up @@ -106,7 +105,7 @@ func (r *systemResource) Create(ctx context.Context, req resource.CreateRequest,
Name: plan.Name.ValueString(),
Slug: plan.Slug.ValueString(),
Description: getDescription(plan.Description.ValueStringPointer()),
WorkspaceId: r.workspaceID,
WorkspaceId: r.workspace,
})
if err != nil {
resp.Diagnostics.AddError("Failed to create system", fmt.Sprintf("Failed to create system: %s", err))
Expand Down Expand Up @@ -244,14 +243,24 @@ func (r *systemResource) Delete(ctx context.Context, req resource.DeleteRequest,
return
}

clientResp, err := r.client.DeleteSystem(ctx, state.Id.ValueString())
clientResp, err := r.client.DeleteSystemWithResponse(ctx, state.Id.ValueString())
if err != nil {
resp.Diagnostics.AddError("Failed to delete system", fmt.Sprintf("Failed to delete system: %s", err))
return
}

if clientResp.StatusCode != http.StatusOK {
resp.Diagnostics.AddError("Failed to delete system", fmt.Sprintf("Failed to delete system: %s", clientResp.Status))
if clientResp.JSON404 != nil && clientResp.JSON404.Error != nil {
resp.Diagnostics.AddError("Failed to delete system", fmt.Sprintf("Failed to delete system: %s", *clientResp.JSON404.Error))
return
}

if clientResp.JSON500 != nil && clientResp.JSON500.Error != nil {
resp.Diagnostics.AddError("Failed to delete system", fmt.Sprintf("Failed to delete system: %s", *clientResp.JSON500.Error))
return
}

if clientResp.JSON200 == nil {
resp.Diagnostics.AddError("Failed to delete system", fmt.Sprintf("Failed to delete system: %s", clientResp.Status()))
return
}
}

0 comments on commit 335cb41

Please sign in to comment.