From 78b12205587fe839f10d946ea3fdc06719decb05 Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Mon, 13 Jan 2020 16:50:05 -0500 Subject: [PATCH] Remove config.go and update things using its aliases --- checkpoint.go | 5 +++-- commands.go | 6 +++--- config.go | 37 ------------------------------------- main.go | 3 ++- plugins.go | 4 +++- 5 files changed, 11 insertions(+), 44 deletions(-) delete mode 100644 config.go diff --git a/checkpoint.go b/checkpoint.go index 4837e4763f..5885bb345e 100644 --- a/checkpoint.go +++ b/checkpoint.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/go-checkpoint" "github.com/hashicorp/terraform/command" + "github.com/hashicorp/terraform/command/cliconfig" ) func init() { @@ -17,7 +18,7 @@ var checkpointResult chan *checkpoint.CheckResponse // runCheckpoint runs a HashiCorp Checkpoint request. You can read about // Checkpoint here: https://github.com/hashicorp/go-checkpoint. -func runCheckpoint(c *Config) { +func runCheckpoint(c *cliconfig.Config) { // If the user doesn't want checkpoint at all, then return. if c.DisableCheckpoint { log.Printf("[INFO] Checkpoint disabled. Not running.") @@ -25,7 +26,7 @@ func runCheckpoint(c *Config) { return } - configDir, err := ConfigDir() + configDir, err := cliconfig.ConfigDir() if err != nil { log.Printf("[ERR] Checkpoint setup error: %s", err) checkpointResult <- nil diff --git a/commands.go b/commands.go index b72c5e8560..ea730e11f8 100644 --- a/commands.go +++ b/commands.go @@ -6,7 +6,7 @@ import ( "github.com/mitchellh/cli" - "github.com/hashicorp/terraform-svchost" + svchost "github.com/hashicorp/terraform-svchost" "github.com/hashicorp/terraform-svchost/auth" "github.com/hashicorp/terraform-svchost/disco" "github.com/hashicorp/terraform/command" @@ -37,7 +37,7 @@ const ( OutputPrefix = "o:" ) -func initCommands(config *Config, services *disco.Disco) { +func initCommands(config *cliconfig.Config, services *disco.Disco) { var inAutomation bool if v := os.Getenv(runningInAutomationEnvName); v != "" { inAutomation = true @@ -390,7 +390,7 @@ func makeShutdownCh() <-chan struct{} { return resultCh } -func credentialsSource(config *Config) (auth.CredentialsSource, error) { +func credentialsSource(config *cliconfig.Config) (auth.CredentialsSource, error) { helperPlugins := pluginDiscovery.FindPlugins("credentials", globalPluginDirs()) return config.CredentialsSource(helperPlugins) } diff --git a/config.go b/config.go deleted file mode 100644 index a3ff1e88ea..0000000000 --- a/config.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -// This file has some compatibility aliases/wrappers for functionality that -// has now moved into command/cliconfig . -// -// Don't add anything new here! If new functionality is needed, better to just -// add it in command/cliconfig and then call there directly. - -import ( - "github.com/hashicorp/terraform/command/cliconfig" - "github.com/hashicorp/terraform/tfdiags" -) - -//go:generate go run ./scripts/generate-plugins.go - -// Config is the structure of the configuration for the Terraform CLI. -// -// This is not the configuration for Terraform itself. That is in the -// "configs" package. -type Config = cliconfig.Config - -// ConfigHost is the structure of the "host" nested block within the CLI -// configuration, which can be used to override the default service host -// discovery behavior for a particular hostname. -type ConfigHost = cliconfig.ConfigHost - -// ConfigDir returns the configuration directory for Terraform. -func ConfigDir() (string, error) { - return cliconfig.ConfigDir() -} - -// LoadConfig reads the CLI configuration from the various filesystem locations -// and from the environment, returning a merged configuration along with any -// diagnostics (errors and warnings) encountered along the way. -func LoadConfig() (*Config, tfdiags.Diagnostics) { - return cliconfig.LoadConfig() -} diff --git a/main.go b/main.go index 628e1447d2..3fbd4cbcc1 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/go-plugin" "github.com/hashicorp/terraform-svchost/disco" + "github.com/hashicorp/terraform/command/cliconfig" "github.com/hashicorp/terraform/command/format" "github.com/hashicorp/terraform/helper/logging" "github.com/hashicorp/terraform/httpclient" @@ -125,7 +126,7 @@ func wrappedMain() int { log.Printf("[INFO] Go runtime version: %s", runtime.Version()) log.Printf("[INFO] CLI args: %#v", os.Args) - config, diags := LoadConfig() + config, diags := cliconfig.LoadConfig() if len(diags) > 0 { // Since we haven't instantiated a command.Meta yet, we need to do // some things manually here and use some "safe" defaults for things diff --git a/plugins.go b/plugins.go index cf2d542535..47ae2e4f61 100644 --- a/plugins.go +++ b/plugins.go @@ -5,6 +5,8 @@ import ( "log" "path/filepath" "runtime" + + "github.com/hashicorp/terraform/command/cliconfig" ) // globalPluginDirs returns directories that should be searched for @@ -16,7 +18,7 @@ import ( func globalPluginDirs() []string { var ret []string // Look in ~/.terraform.d/plugins/ , or its equivalent on non-UNIX - dir, err := ConfigDir() + dir, err := cliconfig.ConfigDir() if err != nil { log.Printf("[ERROR] Error finding global config directory: %s", err) } else {