@@ -3,9 +3,12 @@ package transformation
33import  (
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
133152func  (r  * transformationResource ) ImportState (ctx  context.Context , req  resource.ImportStateRequest , resp  * resource.ImportStateResponse ) {
0 commit comments