Skip to content

Commit

Permalink
Move checking for unmanaged config secrets from the read to the update
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Mar 1, 2023
1 parent 813398f commit ed875de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
28 changes: 25 additions & 3 deletions internal/auth0/connection/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func expandConnection(d *schema.ResourceData) (*management.Connection, diag.Diag
config.GetAttr("options").ForEachElement(func(_ cty.Value, options cty.Value) (stop bool) {
switch strategy {
case management.ConnectionStrategyAuth0:
connection.Options, diagnostics = expandConnectionOptionsAuth0(options)
connection.Options, diagnostics = expandConnectionOptionsAuth0(d, options)
case management.ConnectionStrategyGoogleOAuth2:
connection.Options, diagnostics = expandConnectionOptionsGoogleOAuth2(d, options)
case management.ConnectionStrategyGoogleApps:
Expand Down Expand Up @@ -140,7 +140,10 @@ func expandConnectionOptionsGitHub(
return options, diag.FromErr(err)
}

func expandConnectionOptionsAuth0(config cty.Value) (*management.ConnectionOptions, diag.Diagnostics) {
func expandConnectionOptionsAuth0(
d *schema.ResourceData,
config cty.Value,
) (*management.ConnectionOptions, diag.Diagnostics) {
options := &management.ConnectionOptions{
PasswordPolicy: value.String(config.GetAttr("password_policy")),
NonPersistentAttrs: value.Strings(config.GetAttr("non_persistent_attrs")),
Expand Down Expand Up @@ -270,8 +273,27 @@ func expandConnectionOptionsAuth0(config cty.Value) (*management.ConnectionOptio

var err error
options.UpstreamParams, err = value.MapFromJSON(config.GetAttr("upstream_params"))
if err != nil {
return nil, diag.FromErr(err)
}

return options, diag.FromErr(err)
if !d.IsNewResource() {
dbSecretConfig, ok := d.GetOk("options.0.configuration")
if !ok {
dbSecretConfig = make(map[string]interface{})
}

diags := checkForUnmanagedConfigurationSecrets(
dbSecretConfig.(map[string]interface{}),
options.GetConfiguration(),
)

if diags.HasError() {
return nil, diags
}
}

return options, nil
}

func expandConnectionOptionsGoogleOAuth2(
Expand Down
7 changes: 1 addition & 6 deletions internal/auth0/connection/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,7 @@ func flattenConnectionOptionsAuth0(
}
m["upstream_params"] = upstreamParams

diags := checkForUnmanagedConfigurationSecrets(
dbSecretConfig.(map[string]interface{}),
options.GetConfiguration(),
)

return m, diags
return m, nil
}

// checkForUnmanagedConfigurationSecrets is used to assess keys diff because values are sent back encrypted.
Expand Down

0 comments on commit ed875de

Please sign in to comment.