From 0d614a8d0145dca2f36bc611e29ad67aa7294387 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Fri, 12 Jun 2020 12:39:15 -0400 Subject: [PATCH] command/apply: Remove implicit init call The positional argument passed to apply was once used to specify a source for a Terraform module to fetch and initialize (#337). This functionality was removed from the init command later (#15032) but not completely removed from apply. This code was non-functional but largely not harmful, except for a very specific case: when passing an absolute path to a plan file as the positional argument on Windows, the getter.Detect code would incorrectly interpret the path as a URL. This caused init to fail and the apply command would exit with code 1 but without diagnostics. This commit removes this codepath, which fixes this bug, and should otherwise have no effect on the supported behaviour of apply. --- command/apply.go | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/command/apply.go b/command/apply.go index cee0e0d38..f9ccddfc1 100644 --- a/command/apply.go +++ b/command/apply.go @@ -3,11 +3,9 @@ package command import ( "bytes" "fmt" - "os" "sort" "strings" - "github.com/hashicorp/go-getter" "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/configs/hcl2shim" @@ -53,11 +51,7 @@ func (c *ApplyCommand) Run(args []string) int { var diags tfdiags.Diagnostics - // Get the args. The "maybeInit" flag tracks whether we may need to - // initialize the configuration from a remote path. This is true as long - // as we have an argument. args = cmdFlags.Args() - maybeInit := len(args) == 1 configPath, err := ModulePath(args) if err != nil { c.Ui.Error(err.Error()) @@ -70,32 +64,6 @@ func (c *ApplyCommand) Run(args []string) int { return 1 } - if !c.Destroy && maybeInit { - // We need the pwd for the getter operation below - pwd, err := os.Getwd() - if err != nil { - c.Ui.Error(fmt.Sprintf("Error getting pwd: %s", err)) - return 1 - } - - // Do a detect to determine if we need to do an init + apply. - if detected, err := getter.Detect(configPath, pwd, getter.Detectors); err != nil { - c.Ui.Error(fmt.Sprintf("Invalid path: %s", err)) - return 1 - } else if !strings.HasPrefix(detected, "file") { - // If this isn't a file URL then we're doing an init + - // apply. - var init InitCommand - init.Meta = c.Meta - if code := init.Run([]string{detected}); code != 0 { - return code - } - - // Change the config path to be the cwd - configPath = pwd - } - } - // Check if the path is a plan planFile, err := c.PlanFile(configPath) if err != nil {