Skip to content

Commit 1f038aa

Browse files
committed
change terraform download warning to debug log
1 parent 5213129 commit 1f038aa

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

provisioner/terraform/install.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,24 @@ func Install(ctx context.Context, log slog.Logger, dir string, wantVersion *vers
6464
Version: TerraformVersion,
6565
}
6666
installer.SetLogger(slog.Stdlib(ctx, log, slog.LevelDebug))
67-
log.Debug(
68-
ctx,
69-
"installing terraform",
70-
slog.F("prev_version", hasVersionStr),
71-
slog.F("dir", dir),
72-
slog.F("version", TerraformVersion),
73-
)
67+
68+
logInstallCtx, logInstallCancel := context.WithCancel(ctx)
69+
go func() {
70+
// If the installation is taking too long, log a notice.
71+
select {
72+
case <-time.After(10 * time.Second):
73+
log.Info(
74+
logInstallCtx,
75+
"installing terraform",
76+
slog.F("prev_version", hasVersionStr),
77+
slog.F("dir", dir),
78+
slog.F("version", TerraformVersion),
79+
)
80+
case <-logInstallCtx.Done():
81+
return
82+
}
83+
}()
84+
defer logInstallCancel()
7485

7586
path, err := installer.Install(ctx)
7687
if err != nil {

provisioner/terraform/serve.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
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 {
4142
ExitTimeout time.Duration
4243
}
4344

45+
var loggedVersion atomic.Bool
46+
4447
func absoluteBinaryPath(ctx context.Context, logger slog.Logger) (string, error) {
4548
binaryPath, err := safeexec.LookPath("terraform")
4649
if err != nil {
@@ -63,10 +66,14 @@ func absoluteBinaryPath(ctx context.Context, logger slog.Logger) (string, error)
6366
return "", 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

7178
if installedVersion.LessThan(minTerraformVersion) {
7279
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 {
97104
return 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))
103107
binPath, err := Install(ctx, options.Logger, options.CachePath, TerraformVersion)
104108
if err != nil {
105109
return xerrors.Errorf("install terraform: %w", err)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy