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 1 commit
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
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
4 changes: 2 additions & 2 deletions internal/auth0/action/resource.go
Original file line number Diff line number Diff line change
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
Loading