github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/command.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package command 5 6 import ( 7 "fmt" 8 "os" 9 "runtime" 10 ) 11 12 // Set to true when we're testing 13 var test bool = false 14 15 // DefaultDataDir is the default directory for storing local data. 16 const DefaultDataDir = ".terraform" 17 18 // PluginPathFile is the name of the file in the data dir which stores the list 19 // of directories supplied by the user with the `-plugin-dir` flag during init. 20 const PluginPathFile = "plugin_path" 21 22 // pluginMachineName is the directory name used in new plugin paths. 23 const pluginMachineName = runtime.GOOS + "_" + runtime.GOARCH 24 25 // DefaultPluginVendorDir is the location in the config directory to look for 26 // user-added plugin binaries. Terraform only reads from this path if it 27 // exists, it is never created by terraform. 28 const DefaultPluginVendorDir = "terraform.d/plugins/" + pluginMachineName 29 30 // DefaultStateFilename is the default filename used for the state file. 31 const DefaultStateFilename = "terraform.tfstate" 32 33 // DefaultVarsFilename is the default filename used for vars 34 const DefaultVarsFilename = "terraform.tfvars" 35 36 // DefaultBackupExtension is added to the state file to form the path 37 const DefaultBackupExtension = ".backup" 38 39 // DefaultParallelism is the limit Terraform places on total parallel 40 // operations as it walks the dependency graph. 41 const DefaultParallelism = 10 42 43 // ErrUnsupportedLocalOp is the common error message shown for operations 44 // that require a backend.Local. 45 const ErrUnsupportedLocalOp = `The configured backend doesn't support this operation. 46 47 The "backend" in Terraform defines how Terraform operates. The default 48 backend performs all operations locally on your machine. Your configuration 49 is configured to use a non-local backend. This backend doesn't support this 50 operation. 51 ` 52 53 // ModulePath returns the path to the root module and validates CLI arguments. 54 // 55 // This centralizes the logic for any commands that previously accepted 56 // a module path via CLI arguments. This will error if any extraneous arguments 57 // are given and suggest using the -chdir flag instead. 58 // 59 // If your command accepts more than one arg, then change the slice bounds 60 // to pass validation. 61 func ModulePath(args []string) (string, error) { 62 // TODO: test 63 64 if len(args) > 0 { 65 return "", fmt.Errorf("Too many command line arguments. Did you mean to use -chdir?") 66 } 67 68 path, err := os.Getwd() 69 if err != nil { 70 return "", fmt.Errorf("Error getting pwd: %s", err) 71 } 72 73 return path, nil 74 }