Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(entity): added delete_dependents for entity #184

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.history
.vscode/
.env
local/
Expand Down
1 change: 1 addition & 0 deletions docs/resources/port_entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Entity resource
- `run_id` (String) The runID of the action run that created the entity
- `teams` (List of String) The teams the entity belongs to
- `title` (String) The title of the entity
- `delete_dependents` (Boolean) On delete, also delete the entity dependents

### Read-Only

Expand Down
13 changes: 9 additions & 4 deletions internal/cli/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ func (c *PortClient) UpdateEntity(ctx context.Context, id string, blueprint stri
return &pb.Entity, nil
}

func (c *PortClient) DeleteEntity(ctx context.Context, id string, blueprint string) error {
func (c *PortClient) DeleteEntity(ctx context.Context, id string, blueprint string, deleteDependents bool) error {
url := "v1/blueprints/{blueprint}/entities/{identifier}"
pb := &PortBody{}
resp, err := c.Client.R().
request := c.Client.R().
SetHeader("Accept", "application/json").
SetPathParam("blueprint", blueprint).
SetPathParam("identifier", id).
SetResult(pb).
Delete(url)
SetResult(pb)

if deleteDependents {
request.SetQueryParam("delete_dependents", "true")
}

resp, err := request.Delete(url)
if err != nil {
return err
}
Expand Down
27 changes: 14 additions & 13 deletions port/entity/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ type RelationModel struct {
}

type EntityModel struct {
ID types.String `tfsdk:"id"`
Identifier types.String `tfsdk:"identifier"`
Blueprint types.String `tfsdk:"blueprint"`
Title types.String `tfsdk:"title"`
Icon types.String `tfsdk:"icon"`
RunID types.String `tfsdk:"run_id"`
CreatedAt types.String `tfsdk:"created_at"`
CreatedBy types.String `tfsdk:"created_by"`
UpdatedAt types.String `tfsdk:"updated_at"`
UpdatedBy types.String `tfsdk:"updated_by"`
Properties *EntityPropertiesModel `tfsdk:"properties"`
Teams []types.String `tfsdk:"teams"`
Relations *RelationModel `tfsdk:"relations"`
ID types.String `tfsdk:"id"`
Identifier types.String `tfsdk:"identifier"`
Blueprint types.String `tfsdk:"blueprint"`
Title types.String `tfsdk:"title"`
Icon types.String `tfsdk:"icon"`
RunID types.String `tfsdk:"run_id"`
CreatedAt types.String `tfsdk:"created_at"`
CreatedBy types.String `tfsdk:"created_by"`
UpdatedAt types.String `tfsdk:"updated_at"`
UpdatedBy types.String `tfsdk:"updated_by"`
Properties *EntityPropertiesModel `tfsdk:"properties"`
Teams []types.String `tfsdk:"teams"`
Relations *RelationModel `tfsdk:"relations"`
DeleteDependents types.Bool `tfsdk:"delete_dependents"`
}
4 changes: 2 additions & 2 deletions port/entity/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *EntityResource) Update(ctx context.Context, req resource.UpdateRequest,

if isBlueprintChanged {
// Delete the old entity
err := r.portClient.DeleteEntity(ctx, previousState.Identifier.ValueString(), previousState.Blueprint.ValueString())
err := r.portClient.DeleteEntity(ctx, previousState.Identifier.ValueString(), previousState.Blueprint.ValueString(), previousState.DeleteDependents.ValueBool())
if err != nil {
resp.Diagnostics.AddError("failed to delete entity", err.Error())
return
Expand All @@ -177,7 +177,7 @@ func (r *EntityResource) Delete(ctx context.Context, req resource.DeleteRequest,
return
}

err := r.portClient.DeleteEntity(ctx, state.Identifier.ValueString(), state.Blueprint.ValueString())
err := r.portClient.DeleteEntity(ctx, state.Identifier.ValueString(), state.Blueprint.ValueString(), state.DeleteDependents.ValueBool())

if err != nil {
resp.Diagnostics.AddError("failed to delete entity", err.Error())
Expand Down
Loading