4
4
"context"
5
5
"path/filepath"
6
6
"sync"
7
+ "time"
7
8
8
9
"github.com/cli/safeexec"
9
10
"github.com/hashicorp/go-version"
26
27
terraformMinorVersionMismatch = xerrors .New ("Terraform binary minor version mismatch." )
27
28
)
28
29
30
+ const (
31
+ defaultExitTimeout = 5 * time .Minute
32
+ )
33
+
29
34
type ServeOptions struct {
30
35
* provisionersdk.ServeOptions
31
36
@@ -34,6 +39,17 @@ type ServeOptions struct {
34
39
BinaryPath string
35
40
CachePath string
36
41
Logger slog.Logger
42
+
43
+ // ExitTimeout defines how long we will wait for a running Terraform
44
+ // command to exit (cleanly) if the provision was stopped. This only
45
+ // happens when the command is still running after the provision
46
+ // stream is closed. If the provision is canceled via RPC, this
47
+ // timeout will not be used.
48
+ //
49
+ // This is a no-op on Windows where the process can't be interrupted.
50
+ //
51
+ // Default value: 5 minutes.
52
+ ExitTimeout time.Duration
37
53
}
38
54
39
55
func absoluteBinaryPath (ctx context.Context ) (string , error ) {
@@ -92,10 +108,14 @@ func Serve(ctx context.Context, options *ServeOptions) error {
92
108
options .BinaryPath = absoluteBinary
93
109
}
94
110
}
111
+ if options .ExitTimeout == 0 {
112
+ options .ExitTimeout = defaultExitTimeout
113
+ }
95
114
return provisionersdk .Serve (ctx , & server {
96
- binaryPath : options .BinaryPath ,
97
- cachePath : options .CachePath ,
98
- logger : options .Logger ,
115
+ binaryPath : options .BinaryPath ,
116
+ cachePath : options .CachePath ,
117
+ logger : options .Logger ,
118
+ exitTimeout : options .ExitTimeout ,
99
119
}, options .ServeOptions )
100
120
}
101
121
@@ -107,6 +127,8 @@ type server struct {
107
127
binaryPath string
108
128
cachePath string
109
129
logger slog.Logger
130
+
131
+ exitTimeout time.Duration
110
132
}
111
133
112
134
func (s * server ) executor (workdir string ) executor {
0 commit comments