Skip to content

Commit

Permalink
Merge pull request #107 from ctrombley/fix/fail-fast-on-action-build-…
Browse files Browse the repository at this point in the history
…failure

fix: fail fast when action fails to build
  • Loading branch information
sergiught authored Mar 31, 2022
2 parents 8df1682 + f687406 commit 73617b5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
16 changes: 14 additions & 2 deletions auth0/resource_auth0_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
50 changes: 50 additions & 0 deletions auth0/resource_auth0_action_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package auth0

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -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}}"
Expand Down Expand Up @@ -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
}
`

0 comments on commit 73617b5

Please sign in to comment.