Factor out the validate function for connection limits

This commit is contained in:
Sean Chittenden 2016-09-05 23:39:22 -07:00
parent 02dea2edd9
commit 242405bdf1
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
1 changed files with 13 additions and 10 deletions

View File

@ -56,14 +56,9 @@ func resourcePostgreSQLDatabase() *schema.Resource {
"connection_limit": { "connection_limit": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Description: "How many concurrent connections can be made to this database.", Computed: true,
ValidateFunc: func(v interface{}, key string) (warnings []string, errors []error) { Description: "How many concurrent connections can be made to this database",
value := v.(int) ValidateFunc: validateConnLimit,
if value < -1 {
errors = append(errors, fmt.Errorf("%d can not be less than -1", key))
}
return
},
}, },
"allow_connections": { "allow_connections": {
Type: schema.TypeBool, Type: schema.TypeBool,
@ -81,6 +76,14 @@ func resourcePostgreSQLDatabase() *schema.Resource {
} }
} }
func validateConnLimit(v interface{}, key string) (warnings []string, errors []error) {
value := v.(int)
if value < -1 {
errors = append(errors, fmt.Errorf("%d can not be less than -1", key))
}
return
}
func resourcePostgreSQLDatabaseCreate(d *schema.ResourceData, meta interface{}) error { func resourcePostgreSQLDatabaseCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client) client := meta.(*Client)
conn, err := client.Connect() conn, err := client.Connect()