mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 17:01:04 -06:00
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.
This commit is contained in:
parent
08b735984a
commit
0d614a8d01
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user