| 51 | } |
| 52 | |
| 53 | func systemBinary(ctx context.Context) (*systemBinaryDetails, error) { |
| 54 | binaryPath, err := safeexec.LookPath("terraform") |
| 55 | if err != nil { |
| 56 | return nil, xerrors.Errorf("Terraform binary not found: %w", err) |
| 57 | } |
| 58 | |
| 59 | // If the "coder" binary is in the same directory as |
| 60 | // the "terraform" binary, "terraform" is returned. |
| 61 | // |
| 62 | // We must resolve the absolute path for other processes |
| 63 | // to execute this properly! |
| 64 | absoluteBinary, err := filepath.Abs(binaryPath) |
| 65 | if err != nil { |
| 66 | return nil, xerrors.Errorf("Terraform binary absolute path not found: %w", err) |
| 67 | } |
| 68 | |
| 69 | // Checking the installed version of Terraform. |
| 70 | installedVersion, err := versionFromBinaryPath(ctx, absoluteBinary) |
| 71 | if err != nil { |
| 72 | return nil, xerrors.Errorf("Terraform binary get version failed: %w", err) |
| 73 | } |
| 74 | |
| 75 | details := &systemBinaryDetails{ |
| 76 | absolutePath: absoluteBinary, |
| 77 | version: installedVersion, |
| 78 | } |
| 79 | |
| 80 | if installedVersion.LessThan(minTerraformVersion) { |
| 81 | return details, errTerraformMinorVersionMismatch |
| 82 | } |
| 83 | |
| 84 | return details, nil |
| 85 | } |
| 86 | |
| 87 | // Serve starts a dRPC server on the provided transport speaking Terraform provisioner. |
| 88 | func Serve(ctx context.Context, options *ServeOptions) error { |