Skip to content

Commit

Permalink
feat: support timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Normore committed Feb 21, 2024
1 parent d68f109 commit bdac599
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cmd/deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os/exec"
"strings"
"time"

"github.com/hashicorp/go-tfe"
"github.com/jessevdk/go-flags"
Expand Down Expand Up @@ -41,7 +42,7 @@ func main() {
return
}

deployer, err := getDeployer(opts.TFToken, opts.Organization, opts.Workspace, log)
deployer, err := getDeployer(opts.TFToken, opts.Organization, opts.Workspace, log, opts.Timeout)
if err != nil {
log.Fatal("Could not create deployer", zap.Error(err))
}
Expand All @@ -52,7 +53,7 @@ func main() {
}
}

func getDeployer(token, organization, workspace string, log *zap.Logger) (*deployer.Deployer, error) {
func getDeployer(token, organization, workspace string, log *zap.Logger, timeout time.Duration) (*deployer.Deployer, error) {
tfc, err := tfe.NewClient(&tfe.Config{
Token: token,
})
Expand All @@ -64,6 +65,7 @@ func getDeployer(token, organization, workspace string, log *zap.Logger) (*deplo
return deployer.NewDeployer(context.Background(), log, tfc, &deployer.Config{
Organization: organization,
Workspace: workspace,
WaitTimeout: timeout,
})
}

Expand Down
19 changes: 11 additions & 8 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package options

import "time"

type Options struct {
TFToken string `short:"t" long:"terraform-token" env:"TERRAFORM_TOKEN" description:"Terraform API token"`
Workspace string `short:"w" long:"workspace" env:"TERRAFORM_WORKSPACE" description:"Terraform Workspace"`
Organization string `short:"o" long:"org" env:"TERRAFORM_ORGANIZATION" description:"Terraform Organization"`
VariableName string `short:"n" long:"variable-name" env:"TERRAFORM_VARIABLE_NAME" description:"Terraform Variable Name"`
VariableValue string `short:"v" long:"variable-value" env:"TERRAFORM_VARIABLE_VALUE" description:"Value to set for the Terraform Variable named in VariableName"`
RunTitle string `long:"run-title" env:"TERRAFORM_RUN_TITLE" description:"Title for the Terraform Run. Defaults to latest commit message if unset."`
DryRun bool `long:"dry-run" description:"Do not actually run the Terraform Run. Useful for testing."`
VariableValueRequiredPrefix string `long:"variable-value-required-prefix" env:"VARIABLE_VALUE_REQUIRED_PREFIX" description:"If set, the VariableValue must start with this prefix"`
TFToken string `short:"t" long:"terraform-token" env:"TERRAFORM_TOKEN" description:"Terraform API token"`
Workspace string `short:"w" long:"workspace" env:"TERRAFORM_WORKSPACE" description:"Terraform Workspace"`
Organization string `short:"o" long:"org" env:"TERRAFORM_ORGANIZATION" description:"Terraform Organization"`
VariableName string `short:"n" long:"variable-name" env:"TERRAFORM_VARIABLE_NAME" description:"Terraform Variable Name"`
VariableValue string `short:"v" long:"variable-value" env:"TERRAFORM_VARIABLE_VALUE" description:"Value to set for the Terraform Variable named in VariableName"`
RunTitle string `long:"run-title" env:"TERRAFORM_RUN_TITLE" description:"Title for the Terraform Run. Defaults to latest commit message if unset."`
DryRun bool `long:"dry-run" description:"Do not actually run the Terraform Run. Useful for testing."`
VariableValueRequiredPrefix string `long:"variable-value-required-prefix" env:"VARIABLE_VALUE_REQUIRED_PREFIX" description:"If set, the VariableValue must start with this prefix"`
Timeout time.Duration `long:"timeout" description:"Run timeout"`
}

0 comments on commit bdac599

Please sign in to comment.