From bf48d0132c13dd3a6845a5caa6451ac79d54e2a8 Mon Sep 17 00:00:00 2001 From: Justin Nauman Date: Thu, 17 Nov 2016 17:51:41 -0600 Subject: [PATCH 1/2] Checkpoint signature fixes - Currently the disable_checkpoint setting from $HOME/.terraformrc is never respsected due to: -- The runCheckpoint go routine being fired off prior to loading configuration -- The config.Merge method not actually merging in the c2s settings --- config.go | 2 ++ main.go | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/config.go b/config.go index 3668155d1..dc843a9c6 100644 --- a/config.go +++ b/config.go @@ -183,6 +183,8 @@ func (c1 *Config) Merge(c2 *Config) *Config { } result.Provisioners[k] = v } + result.DisableCheckpoint = c1.DisableCheckpoint || c2.DisableCheckpoint + result.DisableCheckpointSignature = c1.DisableCheckpointSignature || c2.DisableCheckpointSignature return &result } diff --git a/main.go b/main.go index 53bef3d5c..f83d084c5 100644 --- a/main.go +++ b/main.go @@ -103,6 +103,24 @@ func wrappedMain() int { return 1 } + // Load the configuration file if we have one, that can be used to + // define extra providers and provisioners. + clicfgFile, err := cliConfigFile() + if err != nil { + Ui.Error(fmt.Sprintf("Error loading CLI configuration: \n\n%s", err)) + return 1 + } + + if clicfgFile != "" { + usrcfg, err := LoadConfig(clicfgFile) + if err != nil { + Ui.Error(fmt.Sprintf("Error loading CLI configuration: \n\n%s", err)) + return 1 + } + + config = *config.Merge(usrcfg) + } + // Run checkpoint go runCheckpoint(&config) @@ -129,24 +147,6 @@ func wrappedMain() int { HelpWriter: os.Stdout, } - // Load the configuration file if we have one, that can be used to - // define extra providers and provisioners. - clicfgFile, err := cliConfigFile() - if err != nil { - Ui.Error(fmt.Sprintf("Error loading CLI configuration: \n\n%s", err)) - return 1 - } - - if clicfgFile != "" { - usrcfg, err := LoadConfig(clicfgFile) - if err != nil { - Ui.Error(fmt.Sprintf("Error loading CLI configuration: \n\n%s", err)) - return 1 - } - - config = *config.Merge(usrcfg) - } - // Initialize the TFConfig settings for the commands... ContextOpts.Providers = config.ProviderFactories() ContextOpts.Provisioners = config.ProvisionerFactories() From 20a979c36b4d83d669f7075873daea80ddba3d2a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 23 Nov 2016 09:34:05 -0800 Subject: [PATCH 2/2] add tests for checkpoint config merging --- config_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/config_test.go b/config_test.go index fd29ddda1..de64ea0cf 100644 --- a/config_test.go +++ b/config_test.go @@ -66,3 +66,41 @@ func TestConfig_Merge(t *testing.T) { t.Fatalf("bad: %#v", actual) } } + +func TestConfig_Merge_disableCheckpoint(t *testing.T) { + c1 := &Config{ + DisableCheckpoint: true, + } + + c2 := &Config{} + + expected := &Config{ + Providers: map[string]string{}, + Provisioners: map[string]string{}, + DisableCheckpoint: true, + } + + actual := c1.Merge(c2) + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("bad: %#v", actual) + } +} + +func TestConfig_Merge_disableCheckpointSignature(t *testing.T) { + c1 := &Config{ + DisableCheckpointSignature: true, + } + + c2 := &Config{} + + expected := &Config{ + Providers: map[string]string{}, + Provisioners: map[string]string{}, + DisableCheckpointSignature: true, + } + + actual := c1.Merge(c2) + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("bad: %#v", actual) + } +}