diff --git a/api/client/deployment_target.go b/api/client/deployment_target.go index f0c8f1684d..a518ce6ca4 100644 --- a/api/client/deployment_target.go +++ b/api/client/deployment_target.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/google/uuid" "github.com/porter-dev/porter/api/types" ) @@ -49,10 +50,10 @@ func (c *Client) ListDeploymentTargets( func (c *Client) DeleteDeploymentTarget( ctx context.Context, projectId uint, - deploymentTargetName string, + deploymentTargetID uuid.UUID, ) error { return c.deleteRequest( - fmt.Sprintf("/projects/%d/targets/%s", projectId, deploymentTargetName), + fmt.Sprintf("/projects/%d/targets/%s", projectId, deploymentTargetID.String()), nil, nil, ) diff --git a/cli/cmd/commands/target.go b/cli/cmd/commands/target.go index a5fc957a81..c1b1cc1a8e 100644 --- a/cli/cmd/commands/target.go +++ b/cli/cmd/commands/target.go @@ -10,6 +10,7 @@ import ( "text/tabwriter" "github.com/fatih/color" + "github.com/google/uuid" api "github.com/porter-dev/porter/api/client" "github.com/porter-dev/porter/api/types" "github.com/porter-dev/porter/cli/cmd/config" @@ -171,7 +172,24 @@ func deleteTarget(ctx context.Context, _ *types.GetAuthenticatedUserResponse, cl return nil } - err = client.DeleteDeploymentTarget(ctx, cliConf.Project, name) + // assume deletion will be for preview environments only for now + dts, err := client.ListDeploymentTargets(ctx, cliConf.Project, true) + if err != nil { + return fmt.Errorf("error listing targets: %w", err) + } + + var targetID uuid.UUID + for _, dt := range dts.DeploymentTargets { + if dt.Name == name { + targetID = dt.ID + break + } + } + if targetID == uuid.Nil { + return fmt.Errorf("target '%s' not found", name) + } + + err = client.DeleteDeploymentTarget(ctx, cliConf.Project, targetID) if err != nil { return fmt.Errorf("error deleting target: %w", err) }