@@ -39,7 +39,7 @@ type ServeOptions struct {
3939 ExitTimeout time.Duration
4040}
4141
42- func absoluteBinaryPath (ctx context.Context ) (string , error ) {
42+ func absoluteBinaryPath (ctx context.Context , logger slog. Logger ) (string , error ) {
4343 binaryPath , err := safeexec .LookPath ("terraform" )
4444 if err != nil {
4545 return "" , xerrors .Errorf ("Terraform binary not found: %w" , err )
@@ -56,22 +56,37 @@ func absoluteBinaryPath(ctx context.Context) (string, error) {
5656 }
5757
5858 // Checking the installed version of Terraform.
59- version , err := versionFromBinaryPath (ctx , absoluteBinary )
59+ installedVersion , err := versionFromBinaryPath (ctx , absoluteBinary )
6060 if err != nil {
6161 return "" , xerrors .Errorf ("Terraform binary get version failed: %w" , err )
6262 }
6363
64- if version .LessThan (minTerraformVersion ) || version .GreaterThan (maxTerraformVersion ) {
64+ logger .Info (ctx , "detected terraform version" ,
65+ slog .F ("installed_version" , installedVersion .String ()),
66+ slog .F ("min_version" , maxTerraformVersion .String ()),
67+ slog .F ("max_version" , maxTerraformVersion .String ()))
68+
69+ if installedVersion .LessThan (minTerraformVersion ) {
70+ logger .Warn (ctx , "installed terraform version too old, will download known good version to cache" )
6571 return "" , terraformMinorVersionMismatch
6672 }
6773
74+ // Warn if the installed version is newer than what we've decided is the max.
75+ // We used to ignore it and download our own version but this makes it easier
76+ // to test out newer versions of Terraform.
77+ if installedVersion .GreaterThanOrEqual (maxTerraformVersion ) {
78+ logger .Warn (ctx , "installed terraform version newer than expected, you may experience bugs" ,
79+ slog .F ("installed_version" , installedVersion .String ()),
80+ slog .F ("max_version" , maxTerraformVersion .String ()))
81+ }
82+
6883 return absoluteBinary , nil
6984}
7085
7186// Serve starts a dRPC server on the provided transport speaking Terraform provisioner.
7287func Serve (ctx context.Context , options * ServeOptions ) error {
7388 if options .BinaryPath == "" {
74- absoluteBinary , err := absoluteBinaryPath (ctx )
89+ absoluteBinary , err := absoluteBinaryPath (ctx , options . Logger )
7590 if err != nil {
7691 // This is an early exit to prevent extra execution in case the context is canceled.
7792 // It generally happens in unit tests since this method is asynchronous and
@@ -80,6 +95,9 @@ func Serve(ctx context.Context, options *ServeOptions) error {
8095 return xerrors .Errorf ("absolute binary context canceled: %w" , err )
8196 }
8297
98+ options .Logger .Warn (ctx , "no usable terraform binary found, downloading to cache dir" ,
99+ slog .F ("terraform_version" , TerraformVersion .String ()),
100+ slog .F ("cache_dir" , options .CachePath ))
83101 binPath , err := Install (ctx , options .Logger , options .CachePath , TerraformVersion )
84102 if err != nil {
85103 return xerrors .Errorf ("install terraform: %w" , err )
0 commit comments