Skip to content

Commit

Permalink
chore: Update to Go v1.21.9 for compatibility with terraform-plugin-d…
Browse files Browse the repository at this point in the history
…ocs v0.19.2 (#41)

* chore: Update to Go v1.21.9 for compatibility with terraform-plugin-docs v0.19.2

* docs: Update resource name

* refactor: Use crypto/rand instead of deprecated math/rand
  • Loading branch information
alexluong authored May 2, 2024
1 parent be38ad7 commit 5a5a6d6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
golang 1.19
golang 1.21.9
8 changes: 3 additions & 5 deletions docs/resources/webhook_registration.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "webhook_registration Resource - terraform-provider-hookdeck"
page_title: "hookdeck_webhook_registration Resource - terraform-provider-hookdeck"
subcategory: ""
description: |-
Webhook Resource
---

# webhook_registration (Resource)
# hookdeck_webhook_registration (Resource)

Webhook Resource

## Example Usage

```terraform
resource "webhook_registration" "webhook_stripe" {
provider = hookdeck
resource "hookdeck_webhook_registration" "webhook_stripe" {
register = {
request = {
method = "POST"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
resource "webhook_registration" "webhook_stripe" {
provider = hookdeck

resource "hookdeck_webhook_registration" "webhook_stripe" {
register = {
request = {
method = "POST"
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module terraform-provider-hookdeck

go 1.19
go 1.21

toolchain go1.21.9

require (
github.com/hashicorp/terraform-plugin-docs v0.19.2
Expand Down
23 changes: 16 additions & 7 deletions internal/provider/transformation/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package transformation

import (
"context"
"crypto/rand"
"fmt"
"math/rand"
"time"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -137,11 +136,12 @@ func (r *transformationResource) Delete(ctx context.Context, req resource.Delete
// for now, we'll update the transformation to a random ID in this template `deleted-${transformation_name}-${random}`
// so users can still create a new transformation with the old name
length := 10 // length of random key
rand.Seed(time.Now().UnixNano())
b := make([]byte, length+2)
rand.Read(b)
randomizedName := "deleted-" + data.Name.ValueString() + "-" + fmt.Sprintf("%x", b)[2:length+2]
_, err := r.client.Transformation.Update(context.Background(), data.ID.ValueString(), &hookdeck.TransformationUpdateRequest{
randomizedString, err := generateRandomBytes(length)
if err != nil {
resp.Diagnostics.AddError("Error deleting source", err.Error())
}
randomizedName := "deleted-" + data.Name.ValueString() + "-" + fmt.Sprintf("%x", randomizedString)[2:length+2]
_, err = r.client.Transformation.Update(context.Background(), data.ID.ValueString(), &hookdeck.TransformationUpdateRequest{
Name: hookdeck.OptionalOrNull(&randomizedName),
})
if err != nil {
Expand All @@ -153,3 +153,12 @@ func (r *transformationResource) ImportState(ctx context.Context, req resource.I
// Retrieve import ID and save to id attribute
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

func generateRandomBytes(length int) ([]byte, error) {
str := make([]byte, length)
_, err := rand.Read(str)
if err != nil {
return nil, err
}
return str, nil
}
2 changes: 1 addition & 1 deletion internal/provider/webhookregistration/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type webhookRegistrationResource struct {

// Metadata returns the resource type name.
func (r *webhookRegistrationResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = "webhook_registration"
resp.TypeName = req.ProviderTypeName + "_webhook_registration"
}

// Configure adds the provider configured client to the resource.
Expand Down

0 comments on commit 5a5a6d6

Please sign in to comment.