44"context"
55"path/filepath"
66"sync"
7+ "sync/atomic"
78"time"
89
910"github.com/cli/safeexec"
@@ -41,6 +42,8 @@ type ServeOptions struct {
4142ExitTimeout time.Duration
4243}
4344
45+ var loggedVersion atomic.Bool
46+
4447func absoluteBinaryPath (ctx context.Context ,logger slog.Logger ) (string ,error ) {
4548binaryPath ,err := safeexec .LookPath ("terraform" )
4649if err != nil {
@@ -63,10 +66,14 @@ func absoluteBinaryPath(ctx context.Context, logger slog.Logger) (string, error)
6366return "" ,xerrors .Errorf ("Terraform binary get version failed: %w" ,err )
6467}
6568
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+ }
7077
7178if installedVersion .LessThan (minTerraformVersion ) {
7279logger .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 {
97104return xerrors .Errorf ("absolute binary context canceled: %w" ,err )
98105}
99106
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 ))
103107binPath ,err := Install (ctx ,options .Logger ,options .CachePath ,TerraformVersion )
104108if err != nil {
105109return xerrors .Errorf ("install terraform: %w" ,err )