main: instantiate the config and set it up
This commit is contained in:
parent
61f4684931
commit
582229969e
15
config.go
15
config.go
|
@ -67,6 +67,21 @@ func LoadConfig(path string) (*Config, error) {
|
||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge merges two configurations and returns a third entirely
|
||||||
|
// new configuration with the two merged.
|
||||||
|
func (c1 *Config) Merge(c2 *Config) *Config {
|
||||||
|
var result Config
|
||||||
|
result.Providers = make(map[string]string)
|
||||||
|
for k, v := range c1.Providers {
|
||||||
|
result.Providers[k] = v
|
||||||
|
}
|
||||||
|
for k, v := range c2.Providers {
|
||||||
|
result.Providers[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result
|
||||||
|
}
|
||||||
|
|
||||||
// ProviderFactories returns the mapping of prefixes to
|
// ProviderFactories returns the mapping of prefixes to
|
||||||
// ResourceProviderFactory that can be used to instantiate a
|
// ResourceProviderFactory that can be used to instantiate a
|
||||||
// binary-based plugin.
|
// binary-based plugin.
|
||||||
|
|
|
@ -26,3 +26,32 @@ func TestLoadConfig(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", c)
|
t.Fatalf("bad: %#v", c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfig_Merge(t *testing.T) {
|
||||||
|
c1 := &Config{
|
||||||
|
Providers: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"bar": "blah",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
c2 := &Config{
|
||||||
|
Providers: map[string]string{
|
||||||
|
"bar": "baz",
|
||||||
|
"baz": "what",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := &Config{
|
||||||
|
Providers: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"bar": "baz",
|
||||||
|
"baz": "what",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := c1.Merge(c2)
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Fatalf("bad: %#v", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
12
main.go
12
main.go
|
@ -91,6 +91,15 @@ func wrappedMain() int {
|
||||||
log.SetOutput(logOutput)
|
log.SetOutput(logOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load the configuration
|
||||||
|
config := BuiltinConfig
|
||||||
|
|
||||||
|
// Make sure we clean up any managed plugins at the end of this
|
||||||
|
defer plugin.CleanupClients()
|
||||||
|
|
||||||
|
// Initialize the TFConfig settings for the commands...
|
||||||
|
TFConfig.Providers = config.ProviderFactories()
|
||||||
|
|
||||||
// Get the command line args. We shortcut "--version" and "-v" to
|
// Get the command line args. We shortcut "--version" and "-v" to
|
||||||
// just show the version.
|
// just show the version.
|
||||||
args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
|
@ -110,9 +119,6 @@ func wrappedMain() int {
|
||||||
HelpFunc: cli.BasicHelpFunc("terraform"),
|
HelpFunc: cli.BasicHelpFunc("terraform"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we clean up any managed plugins at the end of this
|
|
||||||
defer plugin.CleanupClients()
|
|
||||||
|
|
||||||
exitCode, err := cli.Run()
|
exitCode, err := cli.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
|
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
|
||||||
|
|
Loading…
Reference in New Issue