Skip to content

Commit

Permalink
feat(resource_fusionauth_tenant): add failed authentication action ca…
Browse files Browse the repository at this point in the history
…ncel policy property (#222)

* feat(resource_fusionauth_tenant): add failed authentication action cancel policy property

* chore: lint issue
  • Loading branch information
ludovicthomas authored Jul 13, 2023
1 parent 3528dd3 commit a19b5da
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/resources/tenant.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ resource "fusionauth_tenant" "example" {
- `action_duration_unit` - (Optional) The unit of time associated with a duration.
- `reset_count_in_seconds` - (Optional) The length of time in seconds before the failed authentication count will be reset. Value must be greater than 0.
- `too_many_attempts` - (Optional) The number of failed attempts considered to be too many. Once this threshold is reached the specified User Action will be applied to the user for the duration specified. Value must be greater than 0.
- `action_cancel_policy_on_password_reset` - (Optional) Indicates whether you want the user to be able to self-service unlock their account prior to the action duration by completing a password reset workflow.
- `user_action_id` - (Optional) The Id of the User Action that is applied when the threshold is reached for too many failed authentication attempts.
* `family_configuration` - (Optional)
- `allow_child_registrations` - (Optional) Whether to allow child registrations.
Expand Down
5 changes: 5 additions & 0 deletions fusionauth/resource_fusionauth_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,11 @@ func newFailedAuthenticationConfiguration() *schema.Resource {
Default: "MINUTES",
Description: "The unit of time associated with a duration.",
},
"action_cancel_policy_on_password_reset": {
Type: schema.TypeBool,
Optional: true,
Description: "Indicates whether you want the user to be able to self-service unlock their account prior to the action duration by completing a password reset workflow.",
},
"reset_count_in_seconds": {
Type: schema.TypeInt,
Optional: true,
Expand Down
14 changes: 9 additions & 5 deletions fusionauth/resource_fusionauth_tenant_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func buildTenant(data *schema.ResourceData) (fusionauth.Tenant, diag.Diagnostics
ActionDurationUnit: fusionauth.ExpiryUnit(
data.Get("failed_authentication_configuration.0.action_duration_unit").(string),
),
ActionCancelPolicy: fusionauth.FailedAuthenticationActionCancelPolicy{
OnPasswordReset: data.Get("failed_authentication_configuration.0.action_cancel_policy_on_password_reset").(bool),
},
ResetCountInSeconds: data.Get("failed_authentication_configuration.0.reset_count_in_seconds").(int),
TooManyAttempts: data.Get("failed_authentication_configuration.0.too_many_attempts").(int),
UserActionId: data.Get("failed_authentication_configuration.0.user_action_id").(string),
Expand Down Expand Up @@ -481,11 +484,12 @@ func buildResourceDataFromTenant(t fusionauth.Tenant, data *schema.ResourceData)

err = data.Set("failed_authentication_configuration", []map[string]interface{}{
{
"action_duration": t.FailedAuthenticationConfiguration.ActionDuration,
"action_duration_unit": t.FailedAuthenticationConfiguration.ActionDurationUnit,
"reset_count_in_seconds": t.FailedAuthenticationConfiguration.ResetCountInSeconds,
"too_many_attempts": t.FailedAuthenticationConfiguration.TooManyAttempts,
"user_action_id": t.FailedAuthenticationConfiguration.UserActionId,
"action_duration": t.FailedAuthenticationConfiguration.ActionDuration,
"action_duration_unit": t.FailedAuthenticationConfiguration.ActionDurationUnit,
"action_cancel_policy_on_password_reset": t.FailedAuthenticationConfiguration.ActionCancelPolicy.OnPasswordReset,
"reset_count_in_seconds": t.FailedAuthenticationConfiguration.ResetCountInSeconds,
"too_many_attempts": t.FailedAuthenticationConfiguration.TooManyAttempts,
"user_action_id": t.FailedAuthenticationConfiguration.UserActionId,
},
})
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions fusionauth/resource_fusionauth_tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func testTenantAccTestCheckFuncs(
resource.TestCheckResourceAttr(tfResourcePath, "failed_authentication_configuration.0.action_duration_unit", "DAYS"),
resource.TestCheckResourceAttr(tfResourcePath, "failed_authentication_configuration.0.reset_count_in_seconds", "600"),
resource.TestCheckResourceAttr(tfResourcePath, "failed_authentication_configuration.0.too_many_attempts", "3"),
resource.TestCheckResourceAttr(tfResourcePath, "failed_authentication_configuration.0.action_cancel_policy_on_password_reset", "true"),
// resource.TestCheckResourceAttr(tfResourcePath, "failed_authentication_configuration.0.user_action_id", "UUID"),

// family_configuration
Expand Down Expand Up @@ -544,6 +545,7 @@ resource "fusionauth_tenant" "test_%[1]s" {
action_duration_unit = "DAYS"
reset_count_in_seconds = 600
too_many_attempts = 3
action_cancel_policy_on_password_reset = true
#user_action_id = "UUID"
}
family_configuration {
Expand Down

0 comments on commit a19b5da

Please sign in to comment.