diff --git a/auth0/resource_auth0_hook.go b/auth0/resource_auth0_hook.go index 8fd841ee..bc735ac6 100644 --- a/auth0/resource_auth0_hook.go +++ b/auth0/resource_auth0_hook.go @@ -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, @@ -93,6 +99,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) @@ -148,12 +155,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 { diff --git a/auth0/resource_auth0_hook_test.go b/auth0/resource_auth0_hook_test.go index d3cbe786..61f6fe8f 100644 --- a/auth0/resource_auth0_hook_test.go +++ b/auth0/resource_auth0_hook_test.go @@ -49,6 +49,7 @@ func TestAccHookSecrets(t *testing.T) { Config: testAccHookSecrets("alpha"), 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) { callback(null, { user }); }"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "trigger_id", "pre-user-registration"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "enabled", "true"), @@ -60,6 +61,7 @@ func TestAccHookSecrets(t *testing.T) { Config: testAccHookSecrets2("gamma", "kappa"), 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) { callback(null, { user }); }"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "trigger_id", "pre-user-registration"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "enabled", "true"), @@ -89,7 +91,10 @@ resource "auth0_hook" "my_hook" { script = "function (user, context, callback) { callback(null, { user }); }" trigger_id = "pre-user-registration" enabled = true - secrets = { + dependencies = { + auth0 = "2.30.0" + } + secrets = { foo = "%s" } } @@ -102,6 +107,9 @@ resource "auth0_hook" "my_hook" { name = "pre-user-reg-hook" script = "function (user, context, callback) { callback(null, { user }); }" trigger_id = "pre-user-registration" + dependencies = { + auth0 = "2.30.0" + } enabled = true secrets = { foo = "%s" diff --git a/docs/resources/hook.md b/docs/resources/hook.md index c7499fc5..c41ff41a 100644 --- a/docs/resources/hook.md +++ b/docs/resources/hook.md @@ -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 = <