helper/scheam: support UI defaults
This commit is contained in:
parent
b32470f070
commit
a7c321a028
|
@ -19,10 +19,11 @@ func Provider() *schema.Provider {
|
||||||
return &schema.Provider{
|
return &schema.Provider{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
DefaultFunc: envDefaultFunc("AWS_REGION"),
|
DefaultFunc: envDefaultFunc("AWS_REGION"),
|
||||||
Description: descriptions["region"],
|
Description: descriptions["region"],
|
||||||
|
InputDefault: "us-east-1",
|
||||||
},
|
},
|
||||||
|
|
||||||
"access_key": &schema.Schema{
|
"access_key": &schema.Schema{
|
||||||
|
|
|
@ -82,6 +82,7 @@ func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) {
|
||||||
if opts.Default != "" {
|
if opts.Default != "" {
|
||||||
buf.WriteString(" [bold]Default:[reset] ")
|
buf.WriteString(" [bold]Default:[reset] ")
|
||||||
buf.WriteString(opts.Default)
|
buf.WriteString(opts.Default)
|
||||||
|
buf.WriteString("\n")
|
||||||
}
|
}
|
||||||
buf.WriteString(" [bold]Enter a value:[reset] ")
|
buf.WriteString(" [bold]Enter a value:[reset] ")
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ package schema
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -79,6 +80,9 @@ type Schema struct {
|
||||||
// be formatted to fit a CLI.
|
// be formatted to fit a CLI.
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
|
// InputDefault is the default value to use for when inputs are requested.
|
||||||
|
InputDefault string
|
||||||
|
|
||||||
// The fields below relate to diffs.
|
// The fields below relate to diffs.
|
||||||
//
|
//
|
||||||
// If Computed is true, then the result of this value is computed
|
// If Computed is true, then the result of this value is computed
|
||||||
|
@ -280,7 +284,15 @@ func (m schemaMap) Diff(
|
||||||
func (m schemaMap) Input(
|
func (m schemaMap) Input(
|
||||||
input terraform.UIInput,
|
input terraform.UIInput,
|
||||||
c *terraform.ResourceConfig) (*terraform.ResourceConfig, error) {
|
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
|
// Skip things that don't require config, if that is even valid
|
||||||
// for a provider schema.
|
// for a provider schema.
|
||||||
if !v.Required && !v.Optional {
|
if !v.Required && !v.Optional {
|
||||||
|
@ -623,6 +635,7 @@ func (m schemaMap) inputString(
|
||||||
Id: k,
|
Id: k,
|
||||||
Query: k,
|
Query: k,
|
||||||
Description: schema.Description,
|
Description: schema.Description,
|
||||||
|
Default: schema.InputDefault,
|
||||||
})
|
})
|
||||||
|
|
||||||
return result, err
|
return result, err
|
||||||
|
|
|
@ -22,6 +22,5 @@ type InputOpts struct {
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
// Default will be the value returned if no data is entered.
|
// Default will be the value returned if no data is entered.
|
||||||
Default string
|
Default string
|
||||||
DefaultHidden bool
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue