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

Commit

Permalink
Merge pull request #476 from alexkappa/fix-action-deployment
Browse files Browse the repository at this point in the history
Fix action deployment
  • Loading branch information
alexkappa authored Nov 30, 2021
2 parents 4aa5534 + bb98407 commit 52f1ccc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.24.1

BUG FIXES:

* resource/auth0_action: Secrets would not be created causing deployments to fail ([#473](https://github.com/alexkappa/terraform-provider-auth0/pull/473))

## 0.24.0

ENHANCEMENTS:
Expand Down
26 changes: 16 additions & 10 deletions auth0/resource_auth0_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth0
import (
"fmt"
"net/http"
"strings"

"github.com/alexkappa/terraform-provider-auth0/auth0/internal/hash"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -189,31 +190,36 @@ func updateAction(d *schema.ResourceData, m interface{}) error {
}

func deployAction(d *schema.ResourceData, m interface{}) error {

if d.Get("deploy").(bool) == true {

api := m.(*management.Management)
v, err := api.Action.Deploy(d.Id())
if err != nil {
return err
}
d.Set("version_id", v.GetID())

err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {

a, err := api.Action.Read(d.Id())
if err != nil {
return resource.NonRetryableError(err)
}

if a.DeployedVersion == nil || a.DeployedVersion.GetID() != v.GetID() {
if strings.ToLower(a.GetStatus()) != "built" {
return resource.RetryableError(
fmt.Errorf("Expected deployed version %q to equal %q",
a.DeployedVersion.GetID(),
v.GetID()),
fmt.Errorf(`Expected action status %q to equal "built"`, a.GetStatus()),
)
}

return nil
})
if err != nil {
return fmt.Errorf("Action never reached built state. %w", err)
}

v, err := api.Action.Deploy(d.Id())
if err != nil {
return err
}

d.Set("version_id", v.GetID())
}
return nil
}
Expand Down
24 changes: 24 additions & 0 deletions example/action/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {
required_providers {
auth0 = {
source = "alexkappa/auth0"
version = "0.24.1"
}
}
}

provider "auth0" {}

resource "auth0_action" "do" {
name = "Test Action ${timestamp()}"
supported_triggers {
id = "post-login"
version = "v2"
}
code = <<-EOT
exports.onContinuePostLogin = async (event, api) => {
console.log(event)
};"
EOT
deploy = true
}

0 comments on commit 52f1ccc

Please sign in to comment.