4
4
"context"
5
5
"path/filepath"
6
6
"sync"
7
+ "sync/atomic"
7
8
"time"
8
9
9
10
"github.com/cli/safeexec"
@@ -41,6 +42,8 @@ type ServeOptions struct {
41
42
ExitTimeout time.Duration
42
43
}
43
44
45
+ var loggedVersion atomic.Bool
46
+
44
47
func absoluteBinaryPath (ctx context.Context , logger slog.Logger ) (string , error ) {
45
48
binaryPath , err := safeexec .LookPath ("terraform" )
46
49
if err != nil {
@@ -63,10 +66,14 @@ func absoluteBinaryPath(ctx context.Context, logger slog.Logger) (string, error)
63
66
return "" , xerrors .Errorf ("Terraform binary get version failed: %w" , err )
64
67
}
65
68
66
- logger .Info (ctx , "detected terraform version" ,
67
- slog .F ("installed_version" , installedVersion .String ()),
68
- slog .F ("min_version" , minTerraformVersion .String ()),
69
- slog .F ("max_version" , maxTerraformVersion .String ()))
69
+ // When running in-memory provisioners, each one reaches this point.
70
+ // It's not useful to print this to the user multiple times, so we ensure to log it once.
71
+ if ! loggedVersion .Swap (true ) {
72
+ logger .Info (ctx , "detected terraform version" ,
73
+ slog .F ("installed_version" , installedVersion .String ()),
74
+ slog .F ("min_version" , minTerraformVersion .String ()),
75
+ slog .F ("max_version" , maxTerraformVersion .String ()))
76
+ }
70
77
71
78
if installedVersion .LessThan (minTerraformVersion ) {
72
79
logger .Warn (ctx , "installed terraform version too old, will download known good version to cache" )
@@ -97,9 +104,6 @@ func Serve(ctx context.Context, options *ServeOptions) error {
97
104
return xerrors .Errorf ("absolute binary context canceled: %w" , err )
98
105
}
99
106
100
- options .Logger .Warn (ctx , "no usable terraform binary found, downloading to cache dir" ,
101
- slog .F ("terraform_version" , TerraformVersion .String ()),
102
- slog .F ("cache_dir" , options .CachePath ))
103
107
binPath , err := Install (ctx , options .Logger , options .CachePath , TerraformVersion )
104
108
if err != nil {
105
109
return xerrors .Errorf ("install terraform: %w" , err )
0 commit comments