Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: expose pending tf related options via init opts #619

Merged
merged 3 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

The language server supports the following configuration options:

## `terraformLogFilePath` (`string`)

Path to a file for Terraform executions to be logged into (TF_LOG_PATH)
radeksimko marked this conversation as resolved.
Show resolved Hide resolved
with support for variables (e.g. Timestamp, Pid, Ppid) via Go template
syntax {{.VarName}}

## `terraformExecTimeout` (`string`)

Overrides Terraform execution timeout (e.g. 30s)

Path to the Terraform binary.

## `terraformExecPath` (`string`)

Path to the Terraform binary.
Expand Down
9 changes: 7 additions & 2 deletions internal/cmd/serve_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (c *ServeCommand) flags() *flag.FlagSet {
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", "", "Overrides Terraform execution timeout (e.g. 30s)")
fs.StringVar(&c.tfExecLogPath, "tf-log-file", "", "path to a file for Terraform executions"+
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)"+
Expand Down Expand Up @@ -108,8 +108,12 @@ func (c *ServeCommand) Run(args []string) int {
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 {
Expand All @@ -118,6 +122,7 @@ func (c *ServeCommand) Run(args []string) int {
}
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
Expand Down
24 changes: 22 additions & 2 deletions internal/langserver/handlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"log"
"time"

"github.com/creachadair/jrpc2"
"github.com/creachadair/jrpc2/code"
Expand Down Expand Up @@ -391,11 +392,30 @@ func (svc *service) configureSessionDependencies(cfgOpts *settings.Options) erro
}
svc.srvCtx = lsctx.WithTerraformExecPath(svc.srvCtx, execOpts.ExecPath)

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

timeout, ok := lsctx.TerraformExecTimeout(svc.srvCtx)
if ok {
if len(cfgOpts.TerraformExecTimeout) > 0 {
return fmt.Errorf("Terraform exec timeout can either be set via (-tf-exec-timeout) CLI flag " +
"or (terraformExecTimeout) LSP config option, not both")
}
execOpts.Timeout = timeout
} else if len(cfgOpts.TerraformExecTimeout) > 0 {
d, err := time.ParseDuration(cfgOpts.TerraformExecTimeout)
danishprakash marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("Failed to parse terraformExecTimeout LSP config option: %s", err)
}
execOpts.Timeout = d
}

svc.tfExecOpts = execOpts
Expand Down
7 changes: 3 additions & 4 deletions internal/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ type Options struct {
// ExperimentalFeatures encapsulates experimental features users can opt into.
ExperimentalFeatures ExperimentalFeatures `mapstructure:"experimentalFeatures"`

// TODO: Need to check for conflict with CLI flags
TerraformExecPath string `mapstructure:"terraformExecPath"`
// TerraformExecTimeout time.Duration
// TerraformLogFilePath string
TerraformExecPath string `mapstructure:"terraformExecPath"`
TerraformExecTimeout string `mapstructure:"terraformExecTimeout"`
TerraformLogFilePath string `mapstructure:"terraformLogFilePath"`
}

func (o *Options) Validate() error {
Expand Down