diff --git a/auth0/resource_auth0_action.go b/auth0/resource_auth0_action.go index dd2af758e..c7c30bb95 100644 --- a/auth0/resource_auth0_action.go +++ b/auth0/resource_auth0_action.go @@ -198,16 +198,28 @@ func deployAction(d *schema.ResourceData, m interface{}) error { return resource.NonRetryableError(err) } + if strings.ToLower(action.GetStatus()) == "failed" { + return resource.NonRetryableError( + fmt.Errorf("action %q failed to build, check the Auth0 UI for errors", action.GetName()), + ) + } + if strings.ToLower(action.GetStatus()) != "built" { return resource.RetryableError( - fmt.Errorf(`expected action status %q to equal "built"`, action.GetStatus()), + fmt.Errorf( + "expected action %q status %q to equal %q", + action.GetName(), + action.GetStatus(), + "built", + ), ) } return nil }) + if err != nil { - return fmt.Errorf("action never reached built state: %w", err) + return fmt.Errorf("action %q never reached built state: %w", d.Get("name"), err) } actionVersion, err := api.Action.Deploy(d.Id()) diff --git a/auth0/resource_auth0_action_test.go b/auth0/resource_auth0_action_test.go index 567c96123..ec3894ee2 100644 --- a/auth0/resource_auth0_action_test.go +++ b/auth0/resource_auth0_action_test.go @@ -1,6 +1,8 @@ package auth0 import ( + "fmt" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -46,6 +48,27 @@ func TestAccAction(t *testing.T) { }) } +func TestAccAction_FailedBuild(t *testing.T) { + rand := random.String(6) + + resource.Test(t, resource.TestCase{ + Providers: map[string]terraform.ResourceProvider{ + "auth0": Provider(), + }, + Steps: []resource.TestStep{ + { + Config: random.Template(testAccActionConfigCreateWithFailedBuild, rand), + Check: resource.ComposeTestCheckFunc( + random.TestCheckResourceAttr("auth0_action.my_action", "name", "Test Action {{.random}}", rand), + ), + ExpectError: regexp.MustCompile( + fmt.Sprintf(`action "Test Action %s" failed to build, check the Auth0 UI for errors`, rand), + ), + }, + }, + }) +} + const testAccActionConfigCreate = ` resource auth0_action my_action { name = "Test Action {{.random}}" @@ -92,3 +115,30 @@ resource auth0_action my_action { deploy = true } ` + +// This config makes use of a crypto dependency definition that causes the +// action build to fail. This is presumably because the crypto package has been +// deprecated: https://www.npmjs.com/package/crypto +// +// If this is ever fixed in the API, another means of failing the build will +// need to be used here. +const testAccActionConfigCreateWithFailedBuild = ` +resource auth0_action my_action { + name = "Test Action {{.random}}" + supported_triggers { + id = "post-login" + version = "v2" + } + code = <<-EOT + exports.onContinuePostLogin = async (event, api) => { + console.log(event) + };" + EOT + runtime = "node16" + dependencies { + name = "crypto" + version = "17.7.1" + } + deploy = true +} +`