Skip to content

Commit

Permalink
feat: Add fields storyblok_webhook
Browse files Browse the repository at this point in the history
This adds the fields `description` and `secret` to `storyblok_webhook`
  • Loading branch information
mvantellingen committed May 14, 2024
1 parent 4bfede8 commit 499b32c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20240514-073350.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: Add `description` and `secret` to `storyblok_webhook`
time: 2024-05-14T07:33:50.777468+02:00
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-framework v1.3.4
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/labd/storyblok-go-sdk v0.3.0
github.com/labd/storyblok-go-sdk v0.3.1
github.com/wk8/go-ordered-map/v2 v2.1.8
)

Expand Down
36 changes: 21 additions & 15 deletions internal/webhook/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,38 @@ import (
)

type WebhookModel struct {
ID types.String `tfsdk:"id"`
WebhookID types.Int64 `tfsdk:"webhook_id"`
SpaceID types.Int64 `tfsdk:"space_id"`
Actions []types.String `tfsdk:"actions"`
Name types.String `tfsdk:"name"`
Endpoint types.String `tfsdk:"endpoint"`
Activated types.Bool `tfsdk:"activated"`
ID types.String `tfsdk:"id"`
WebhookID types.Int64 `tfsdk:"webhook_id"`
Description types.String `tfsdk:"description"`
SpaceID types.Int64 `tfsdk:"space_id"`
Actions []types.String `tfsdk:"actions"`
Name types.String `tfsdk:"name"`
Endpoint types.String `tfsdk:"endpoint"`
Activated types.Bool `tfsdk:"activated"`
Secret types.String `tfsdk:"secret"`
}

func (m *WebhookModel) toCreateInput() sbmgmt.CreateWebhookJSONRequestBody {
return sbmgmt.CreateWebhookJSONRequestBody{
WebhookEndpoint: sbmgmt.WebhookCreateInput{
Activated: m.Activated.ValueBool(),
Name: m.Name.ValueString(),
Endpoint: m.Endpoint.ValueString(),
Actions: *utils.ConvertToPointerStringSlice(m.Actions),
Activated: m.Activated.ValueBool(),
Name: m.Name.ValueString(),
Endpoint: m.Endpoint.ValueString(),
Actions: *utils.ConvertToPointerStringSlice(m.Actions),
Secret: m.Secret.ValueString(),
Description: m.Description.ValueStringPointer(),
},
}
}
func (m *WebhookModel) toUpdateInput() sbmgmt.UpdateWebhookJSONRequestBody {
return sbmgmt.UpdateWebhookJSONRequestBody{
WebhookEndpoint: sbmgmt.WebhookUpdateInput{
Activated: m.Activated.ValueBool(),
Name: m.Name.ValueString(),
Endpoint: m.Endpoint.ValueString(),
Actions: *utils.ConvertToPointerStringSlice(m.Actions),
Activated: m.Activated.ValueBool(),
Name: m.Name.ValueString(),
Endpoint: m.Endpoint.ValueString(),
Actions: *utils.ConvertToPointerStringSlice(m.Actions),
Secret: m.Secret.ValueString(),
Description: m.Description.ValueStringPointer(),
},
}
}
Expand Down
9 changes: 9 additions & 0 deletions internal/webhook/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ func (r *webhookResource) Schema(_ context.Context, _ resource.SchemaRequest, re
Required: true,
ElementType: types.StringType,
},
"secret": schema.StringAttribute{
Description: "The secret to sign the webhook payload with.",
Optional: true,
Sensitive: true,
},
"description": schema.StringAttribute{
Description: "The description of the webhook.",
Optional: true,
},
},
}
}
Expand Down

0 comments on commit 499b32c

Please sign in to comment.