helper/scheam: support UI defaults

This commit is contained in:
Mitchell Hashimoto 2014-09-29 14:00:35 -07:00
parent b32470f070
commit a7c321a028
4 changed files with 21 additions and 7 deletions

View File

@ -23,6 +23,7 @@ func Provider() *schema.Provider {
Required: true,
DefaultFunc: envDefaultFunc("AWS_REGION"),
Description: descriptions["region"],
InputDefault: "us-east-1",
},
"access_key": &schema.Schema{

View File

@ -82,6 +82,7 @@ func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) {
if opts.Default != "" {
buf.WriteString(" [bold]Default:[reset] ")
buf.WriteString(opts.Default)
buf.WriteString("\n")
}
buf.WriteString(" [bold]Enter a value:[reset] ")

View File

@ -14,6 +14,7 @@ package schema
import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
@ -79,6 +80,9 @@ type Schema struct {
// be formatted to fit a CLI.
Description string
// InputDefault is the default value to use for when inputs are requested.
InputDefault string
// The fields below relate to diffs.
//
// If Computed is true, then the result of this value is computed
@ -280,7 +284,15 @@ func (m schemaMap) Diff(
func (m schemaMap) Input(
input terraform.UIInput,
c *terraform.ResourceConfig) (*terraform.ResourceConfig, error) {
for k, v := range m {
keys := make([]string, 0, len(m))
for k, _ := range m {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := m[k]
// Skip things that don't require config, if that is even valid
// for a provider schema.
if !v.Required && !v.Optional {
@ -623,6 +635,7 @@ func (m schemaMap) inputString(
Id: k,
Query: k,
Description: schema.Description,
Default: schema.InputDefault,
})
return result, err

View File

@ -23,5 +23,4 @@ type InputOpts struct {
// Default will be the value returned if no data is entered.
Default string
DefaultHidden bool
}