Skip to content

Commit

Permalink
cmd/serve: Remove deprecated -tf-exec-* CLI flags
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jul 22, 2022
1 parent 0dcd4be commit 64f8ce7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 90 deletions.
65 changes: 0 additions & 65 deletions internal/cmd/serve_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"runtime/pprof"
"strings"
"syscall"
"time"

lsctx "github.com/hashicorp/terraform-ls/internal/context"
"github.com/hashicorp/terraform-ls/internal/langserver"
Expand All @@ -28,9 +26,6 @@ type ServeCommand struct {
// flags
port int
logFilePath string
tfExecPath string
tfExecLogPath string
tfExecTimeout string
cpuProfile string
memProfile string
reqConcurrency int
Expand All @@ -42,11 +37,6 @@ func (c *ServeCommand) flags() *flag.FlagSet {
fs.IntVar(&c.port, "port", 0, "port number to listen on (turns server into TCP mode)")
fs.StringVar(&c.logFilePath, "log-file", "", "path to a file to log into with support "+
"for variables (e.g. timestamp, pid, ppid) via Go template syntax {{varName}}")
fs.StringVar(&c.tfExecPath, "tf-exec", "", "(DEPRECATED) path to Terraform binary. Use terraformExecPath LSP config option instead.")
fs.StringVar(&c.tfExecTimeout, "tf-exec-timeout", "", "(DEPRECATED) Overrides Terraform execution timeout (e.g. 30s)")
fs.StringVar(&c.tfExecLogPath, "tf-log-file", "", "(DEPRECATED) path to a file for Terraform executions"+
" to be logged into with support for variables (e.g. timestamp, pid, ppid) via Go template"+
" syntax {{varName}}")
fs.StringVar(&c.cpuProfile, "cpuprofile", "", "file into which to write CPU profile (if not empty)"+
" with support for variables (e.g. timestamp, pid, ppid) via Go template"+
" syntax {{varName}}")
Expand Down Expand Up @@ -99,61 +89,6 @@ func (c *ServeCommand) Run(args []string) int {
os.Interrupt, syscall.SIGTERM)
defer cancelFunc()

// Setting this option as a CLI flag is deprecated
// in favor of `terraformLogFilePath` LSP config option.
// This validation code is duplicated, make changes accordingly.
if c.tfExecLogPath != "" {
err := logging.ValidateExecLogPath(c.tfExecLogPath)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to setup logging for Terraform: %s", err))
return 1
}
ctx = lsctx.WithTerraformExecLogPath(ctx, c.tfExecLogPath)
logger.Printf("Terraform executions will be logged to %s "+
"(interpolated at the time of execution)", c.tfExecLogPath)
logger.Println("[WARN] -tf-log-file is deprecated in favor of `terraformLogFilePath` LSP config option")
}

// Setting this option as a CLI flag is deprecated
// in favor of `terraformExecTimeout` LSP config option.
// This validation code is duplicated, make changes accordingly.
if c.tfExecTimeout != "" {
d, err := time.ParseDuration(c.tfExecTimeout)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to parse Terraform timeout: %s", err))
return 1
}
ctx = lsctx.WithTerraformExecTimeout(ctx, d)
logger.Printf("Terraform execution timeout set to %s", d)
logger.Println("[WARN] -tf-exec-timeout is deprecated in favor of `terraformExecTimeout` LSP config option")
}

// Setting this option as a CLI flag is deprecated
// in favor of `terraformExecPath` LSP config option.
// This validation code is duplicated, make changes accordingly.
if c.tfExecPath != "" {
path := c.tfExecPath

// just some sanity checking here, no need to get too specific otherwise will be complex cross-OS
if !filepath.IsAbs(path) {
c.Ui.Error(fmt.Sprintf("Expected absolute path for Terraform binary, got %q", path))
return 1
}
stat, err := os.Stat(path)
if err != nil {
c.Ui.Error(fmt.Sprintf("Unable to find Terraform binary: %s", err))
return 1
}
if stat.IsDir() {
c.Ui.Error(fmt.Sprintf("Expected a Terraform binary, got a directory: %q", path))
return 1
}

ctx = lsctx.WithTerraformExecPath(ctx, path)
logger.Printf("Terraform exec path set to %q", path)
logger.Println("[WARN] -tf-exec is deprecated in favor of `terraformExecPath` LSP config option")
}

if c.reqConcurrency != 0 {
ctx = langserver.WithRequestConcurrency(ctx, c.reqConcurrency)
logger.Printf("Custom request concurrency set to %d", c.reqConcurrency)
Expand Down
29 changes: 4 additions & 25 deletions internal/langserver/handlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,7 @@ func (svc *service) configureSessionDependencies(ctx context.Context, cfgOpts *s

// The following is set via CLI flags, hence available in the server context
execOpts := &exec.ExecutorOpts{}
cliExecPath, ok := lsctx.TerraformExecPath(svc.srvCtx)
if ok {
if len(cfgOpts.Terraform.Path) > 0 {
return fmt.Errorf("Terraform exec path can either be set via (-tf-exec) CLI flag " +
"or (terraform.path) LSP config option, not both")
}
execOpts.ExecPath = cliExecPath
} else if len(cfgOpts.Terraform.Path) > 0 {
if len(cfgOpts.Terraform.Path) > 0 {
execOpts.ExecPath = cfgOpts.Terraform.Path
} else {
path, err := svc.tfDiscoFunc()
Expand All @@ -414,25 +407,11 @@ func (svc *service) configureSessionDependencies(ctx context.Context, cfgOpts *s
}
svc.srvCtx = lsctx.WithTerraformExecPath(svc.srvCtx, execOpts.ExecPath)

path, ok := lsctx.TerraformExecLogPath(svc.srvCtx)
if ok {
if len(cfgOpts.Terraform.LogFilePath) > 0 {
return fmt.Errorf("Terraform log file path can either be set via (-tf-log-file) CLI flag " +
"or (terraform.logFilePath) LSP config option, not both")
}
execOpts.ExecLogPath = path
} else if len(cfgOpts.Terraform.LogFilePath) > 0 {
if len(cfgOpts.Terraform.LogFilePath) > 0 {
execOpts.ExecLogPath = cfgOpts.Terraform.LogFilePath
}

timeout, ok := lsctx.TerraformExecTimeout(svc.srvCtx)
if ok {
if len(cfgOpts.Terraform.Timeout) > 0 {
return fmt.Errorf("Terraform exec timeout can either be set via (-tf-exec-timeout) CLI flag " +
"or (terraform.timeout) LSP config option, not both")
}
execOpts.Timeout = timeout
} else if len(cfgOpts.Terraform.Timeout) > 0 {
if len(cfgOpts.Terraform.Timeout) > 0 {
d, err := time.ParseDuration(cfgOpts.Terraform.Timeout)
if err != nil {
return fmt.Errorf("Failed to parse terraform.timeout LSP config option: %s", err)
Expand Down Expand Up @@ -474,7 +453,7 @@ func (svc *service) configureSessionDependencies(ctx context.Context, cfgOpts *s

cc, err := ilsp.ClientCapabilities(ctx)
if err == nil {
if _, ok = lsp.ExperimentalClientCapabilities(cc.Experimental).ShowReferencesCommandId(); ok {
if _, ok := lsp.ExperimentalClientCapabilities(cc.Experimental).ShowReferencesCommandId(); ok {
moduleHooks = append(moduleHooks, refreshCodeLens(svc.server))
}

Expand Down

0 comments on commit 64f8ce7

Please sign in to comment.