Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Support hook dependencies #312

Merged
merged 10 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 15 additions & 1 deletion auth0/resource_auth0_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func newHook() *schema.Resource {
ValidateFunc: validateHookNameFunc(),
Description: "Name of this hook",
},
"dependencies": {
Type: schema.TypeMap,
Elem: schema.TypeString,
Optional: true,
Description: "Dependencies of this hook used by webtask server",
},
"script": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -83,6 +89,7 @@ func readHook(d *schema.ResourceData, m interface{}) error {
}

d.Set("name", c.Name)
d.Set("dependencies", c.Dependencies)
d.Set("script", c.Script)
d.Set("trigger_id", c.TriggerID)
d.Set("enabled", c.Enabled)
Expand Down Expand Up @@ -115,12 +122,19 @@ func deleteHook(d *schema.ResourceData, m interface{}) error {
}

func buildHook(d *schema.ResourceData) *management.Hook {
return &management.Hook{
h := &management.Hook{
Name: String(d, "name"),
Script: String(d, "script"),
TriggerID: String(d, "trigger_id", IsNewResource()),
Enabled: Bool(d, "enabled"),
}

deps := Map(d, "dependencies")
if deps != nil {
h.Dependencies = &deps
}

return h
}

func validateHookNameFunc() schema.SchemaValidateFunc {
Expand Down
4 changes: 4 additions & 0 deletions auth0/resource_auth0_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestAccHook(t *testing.T) {
Config: testAccHookUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_hook.my_hook", "name", "pre-user-reg-hook"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.auth0", "2.30.0"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "script", "function (user, context, callback) { console.log(user); callback(null, { user }); }"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "trigger_id", "pre-user-registration"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "enabled", "false"),
Expand All @@ -53,6 +54,9 @@ resource "auth0_hook" "my_hook" {
trigger_id = "pre-user-registration"
script = "function (user, context, callback) { console.log(user); callback(null, { user }); }"
enabled = false
dependencies = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the formatting is off? (tabs v space?)

auth0 = "2.30.0"
}
}
`

Expand Down
11 changes: 8 additions & 3 deletions docs/resources/hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ Depending on the extensibility point, you can use Hooks with Database Connection
resource "auth0_hook" "my_hook" {
name = "My Pre User Registration Hook"
script = <<EOF
function (user, context, callback) {
callback(null, { user });
function (user, context, callback) {
callback(null, { user });
}
EOF
trigger_id = "pre-user-registration"
enabled = true

dependencies = {
auth0 = "2.30.0"
}
}
```

Expand All @@ -35,4 +39,5 @@ The following arguments are supported:
* `enabled` - (Optional) Whether the hook is enabled, or disabled
* `name` - (Required) Name of this hook
* `script` - (Required) Code to be executed when this hook runs
* `trigger_id` - (Required) Execution stage of this rule. Can be credentials-exchange, pre-user-registration, post-user-registration, post-change-password, or send-phone-message
* `trigger_id` - (Required) Execution stage of this rule. Can be credentials-exchange, pre-user-registration, post-user-registration, post-change-password, or send-phone-message
* `dependencies` - (Optional) Dependencies of this hook used by webtask server