Skip to content

Commit

Permalink
provider/mysql: Empty Provider Credentials Caused Panic
Browse files Browse the repository at this point in the history
There are currently no checks on username and endpoint in the provider
schema from being an empty value. This PR adds support to make sure that
endpoint and username are not empty strings as that can cause a panic

Results of the PR:

```
 % terraform apply
There are warnings and/or errors related to your configuration. Please
fix these before continuing.

Errors:

  * provider.mysql: Endpoint must not be an empty string
```
  • Loading branch information
stack72 committed Jun 17, 2016
1 parent 02627e5 commit 7b482cc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions builtin/providers/mysql/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,28 @@ func Provider() terraform.ResourceProvider {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("MYSQL_ENDPOINT", nil),
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if value == "" {
errors = append(errors, fmt.Errorf("Endpoint must not be an empty string"))
}

return
},
},

"username": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("MYSQL_USERNAME", nil),
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if value == "" {
errors = append(errors, fmt.Errorf("Username must not be an empty string"))
}

return
},
},

"password": &schema.Schema{
Expand Down

0 comments on commit 7b482cc

Please sign in to comment.