Skip to content

Commit de618de

Browse files
committed
feat: Delete transformation by obfuscating its name for uniqueness
1 parent 6b8291f commit de618de

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/provider/transformation/resource.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package transformation
33
import (
44
"context"
55
"fmt"
6+
"math/rand"
7+
"time"
68

79
"github.com/hashicorp/terraform-plugin-framework/path"
810
"github.com/hashicorp/terraform-plugin-framework/resource"
11+
hookdeck "github.com/hookdeck/hookdeck-go-sdk"
912
hookdeckClient "github.com/hookdeck/hookdeck-go-sdk/client"
1013
)
1114

@@ -124,10 +127,26 @@ func (r *transformationResource) Delete(ctx context.Context, req resource.Delete
124127
}
125128

126129
// Delete existing resource
130+
// TODO: use delete once the endpoint is ready
127131
// _, err := r.client.Transformation.Delete(context.Background(), data.ID.ValueString())
128132
// if err != nil {
129133
// resp.Diagnostics.AddError("Error deleting source", err.Error())
130134
// }
135+
136+
// TODO: remove later
137+
// for now, we'll update the transformation to a random ID in this template `deleted-${transformation_name}-${random}`
138+
// so users can still create a new transformation with the old name
139+
length := 10 // length of random key
140+
rand.Seed(time.Now().UnixNano())
141+
b := make([]byte, length+2)
142+
rand.Read(b)
143+
randomizedName := "deleted-" + data.Name.ValueString() + "-" + fmt.Sprintf("%x", b)[2:length+2]
144+
_, err := r.client.Transformation.Update(context.Background(), data.ID.ValueString(), &hookdeck.TransformationUpdateRequest{
145+
Name: hookdeck.OptionalOrNull(&randomizedName),
146+
})
147+
if err != nil {
148+
resp.Diagnostics.AddError("Error deleting source", err.Error())
149+
}
131150
}
132151

133152
func (r *transformationResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {

0 commit comments

Comments
 (0)