From 7b482cca9b48deba49ce0662842283f14d2535c7 Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 17 Jun 2016 11:32:30 +0100 Subject: [PATCH] provider/mysql: Empty Provider Credentials Caused Panic 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 ``` --- builtin/providers/mysql/provider.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/builtin/providers/mysql/provider.go b/builtin/providers/mysql/provider.go index 3afd7db4c..bd3401979 100644 --- a/builtin/providers/mysql/provider.go +++ b/builtin/providers/mysql/provider.go @@ -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{