Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HasChange check to action secrets and dependencies #903

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions docs/resources/action.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: |-

Actions are secure, tenant-specific, versioned functions written in Node.js that execute at certain points during the Auth0 runtime. Actions are used to customize and extend Auth0's capabilities with custom logic.

~> Secrets and dependencies must be managed with Terraform, they cannot be managed out-of-band.

## Example Usage

```terraform
Expand Down Expand Up @@ -67,10 +65,10 @@ resource "auth0_action" "my_action" {

### Optional

- `dependencies` (Block Set) List of third party npm modules, and their versions, that this action depends on. If your action contains dependencies, they must be managed through Terraform; dependencies cannot be managed out-of-band. (see [below for nested schema](#nestedblock--dependencies))
- `dependencies` (Block Set) List of third party npm modules, and their versions, that this action depends on. (see [below for nested schema](#nestedblock--dependencies))
- `deploy` (Boolean) Deploying an action will create a new immutable version of the action. If the action is currently bound to a trigger, then the system will begin executing the newly deployed version of the action immediately.
- `runtime` (String) The Node runtime. Defaults to `node18`. Possible values are: `node16` (not recommended), or `node18` (recommended).
- `secrets` (Block List) List of secrets that are included in an action or a version of an action. If your action contains secrets, they **must** be managed through Terraform; Secrets cannot be managed out-of-band. (see [below for nested schema](#nestedblock--secrets))
- `secrets` (Block List) List of secrets that are included in an action or a version of an action. Partial management of secrets is not supported. (see [below for nested schema](#nestedblock--secrets))

### Read-Only

Expand Down
22 changes: 11 additions & 11 deletions internal/auth0/action/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ import (
"github.com/auth0/terraform-provider-auth0/internal/value"
)

func expandAction(config cty.Value) *management.Action {
func expandAction(data *schema.ResourceData) *management.Action {
config := data.GetRawConfig()

action := &management.Action{
Name: value.String(config.GetAttr("name")),
Code: value.String(config.GetAttr("code")),
Runtime: value.String(config.GetAttr("runtime")),
SupportedTriggers: expandActionTriggers(config.GetAttr("supported_triggers")),
Dependencies: expandActionDependencies(config.GetAttr("dependencies")),
Secrets: expandActionSecrets(config.GetAttr("secrets")),
}

if data.HasChange("dependencies") {
action.Dependencies = expandActionDependencies(config.GetAttr("dependencies"))
}

if data.HasChange("secrets") {
action.Secrets = expandActionSecrets(config.GetAttr("secrets"))
}

if action.GetRuntime() == "node18" {
Expand Down Expand Up @@ -50,10 +58,6 @@ func expandActionTriggers(triggers cty.Value) []management.ActionTrigger {
}

func expandActionDependencies(dependencies cty.Value) *[]management.ActionDependency {
if dependencies.IsNull() {
return nil
}

actionDependencies := make([]management.ActionDependency, 0)

dependencies.ForEachElement(func(_ cty.Value, dep cty.Value) (stop bool) {
Expand All @@ -68,10 +72,6 @@ func expandActionDependencies(dependencies cty.Value) *[]management.ActionDepend
}

func expandActionSecrets(secrets cty.Value) *[]management.ActionSecret {
if secrets.IsNull() {
return nil
}

actionSecrets := make([]management.ActionSecret, 0)

secrets.ForEachElement(func(_ cty.Value, secret cty.Value) (stop bool) {
Expand Down
8 changes: 4 additions & 4 deletions internal/auth0/action/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewResource() *schema.Resource {
"dependencies": {
Type: schema.TypeSet,
Optional: true,
Description: "List of third party npm modules, and their versions, that this action depends on. If your action contains dependencies, they must be managed through Terraform; dependencies cannot be managed out-of-band.",
Description: "List of third party npm modules, and their versions, that this action depends on.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -95,7 +95,7 @@ func NewResource() *schema.Resource {
"secrets": {
Type: schema.TypeList,
Optional: true,
Description: "List of secrets that are included in an action or a version of an action. If your action contains secrets, they **must** be managed through Terraform; Secrets cannot be managed out-of-band.",
Description: "List of secrets that are included in an action or a version of an action. Partial management of secrets is not supported.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -133,7 +133,7 @@ func NewResource() *schema.Resource {
func createAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

action := expandAction(data.GetRawConfig())
action := expandAction(data)

if err := api.Action.Create(ctx, action); err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -167,7 +167,7 @@ func updateAction(ctx context.Context, data *schema.ResourceData, meta interface
return diagnostics
}

action := expandAction(data.GetRawConfig())
action := expandAction(data)

if err := api.Action.Update(ctx, data.Id(), action); err != nil {
return diag.FromErr(internalError.HandleAPIError(data, err))
Expand Down
2 changes: 0 additions & 2 deletions templates/resources/action.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: |-

{{ .Description | trimspace }}

~> Secrets and dependencies must be managed with Terraform, they cannot be managed out-of-band.

{{ if .HasExample -}}

## Example Usage
Expand Down
Loading
Loading