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

correctly transfer username validation to auth0 #258

Merged
merged 6 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 27 additions & 5 deletions auth0/resource_auth0_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,31 @@ var connectionSchema = map[string]*schema.Schema{
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"validation": {
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will likely break state for some users. We should write a migration to safely migrate state from a map to a list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats going to take same time as Im new to Go and Terraform Provider Migrations. Will try to provide it within the next few days.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand :) I’m here if you need any help.

For inspiration, you can see the migration of connections schema a while back.

MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"username": {
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"min": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntAtLeast(1),
},
"max": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntAtLeast(1),
},
},
},
},
},
},
Optional: true,
},
"password_policy": {
Expand Down Expand Up @@ -181,9 +204,8 @@ var connectionSchema = map[string]*schema.Schema{
Description: "Indicates whether or not to allow user sign-ups to your application",
},
"requires_username": {
Type: schema.TypeBool,
Optional: true,
Description: "Indicates whether or not the user is required to provide a username in addition to an email address",
Type: schema.TypeBool,
Optional: true,
alexkappa marked this conversation as resolved.
Show resolved Hide resolved
},
"custom_scripts": {
Type: schema.TypeMap,
Expand Down
12 changes: 10 additions & 2 deletions auth0/resource_auth0_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func TestAccConnection(t *testing.T) {
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.import_mode", "false"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.disable_signup", "false"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.requires_username", "true"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.validation.0.username.0.min", "10"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.validation.0.username.0.max", "40"),
resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.custom_scripts.get_user", "myFunction"),
resource.TestCheckResourceAttrSet("auth0_connection.my_connection", "options.0.configuration.foo"),
),
Expand Down Expand Up @@ -110,11 +112,17 @@ resource "auth0_connection" "my_connection" {
password_complexity_options {
min_length = 6
}
validation {
username {
min = 10
max = 40
}
}
requires_username = true
enabled_database_customization = false
brute_force_protection = true
import_mode = false
disable_signup = false
requires_username = true
alexkappa marked this conversation as resolved.
Show resolved Hide resolved
custom_scripts = {
get_user = "myFunction"
}
Expand All @@ -140,11 +148,11 @@ resource "auth0_connection" "my_connection" {
password_no_personal_info {
enable = true
}
requires_username = true
enabled_database_customization = false
brute_force_protection = false
import_mode = false
disable_signup = false
requires_username = true
custom_scripts = {
get_user = "myFunction"
}
Expand Down
11 changes: 10 additions & 1 deletion auth0/structure_auth0_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,19 @@ func expandConnectionOptionsGitHub(d ResourceData) *management.ConnectionOptions
func expandConnectionOptionsAuth0(d ResourceData) *management.ConnectionOptions {

o := &management.ConnectionOptions{
Validation: Map(d, "validation"),
PasswordPolicy: String(d, "password_policy"),
}

List(d, "validation").Elem(func(d ResourceData) {
o.Validation = make(map[string]interface{})
List(d, "username").Elem(func(d ResourceData) {
usernameValidation := make(map[string]*int)
usernameValidation["min"] = Int(d, "min")
usernameValidation["max"] = Int(d, "max")
o.Validation["username"] = usernameValidation
})
})

List(d, "password_history").Elem(func(d ResourceData) {
o.PasswordHistory = make(map[string]interface{})
o.PasswordHistory["enable"] = Bool(d, "enable")
Expand Down