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

@ -54,16 +54,11 @@ func resourcePostgreSQLDatabase() *schema.Resource {
Description: "The name of the tablespace that will be associated with the new database.",
},
"connection_limit": {
Type: schema.TypeInt,
Optional: true,
Description: "How many concurrent connections can be made to this database.",
ValidateFunc: func(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
},
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "How many concurrent connections can be made to this database",
ValidateFunc: validateConnLimit,
},
"allow_connections": {
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 {
client := meta.(*Client)
conn, err := client.Connect()