mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
* feat: Create provisioner abstraction Creates a provisioner abstraction that takes prior art from the Terraform plugin system. It's safe to assume this code will change a lot when it becomes integrated with provisionerd. Closes #10. * Ignore generated files in diff view * Check for unstaged file changes * Install protoc-gen-go * Use proper drpc plugin version * Fix serve closed pipe * Install sqlc with curl for speed * Fix install command * Format CI action * Add linguist-generated and closed pipe test * Cleanup code from comments * Add dRPC comment * Add Terraform installer for cross-platform * Build provisioner tests on Linux only
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package terraform
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
|
|
"github.com/coder/coder/provisionersdk"
|
|
"github.com/hashicorp/go-version"
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
var (
|
|
// The minimum version of Terraform supported by the provisioner.
|
|
// Validation came out in 0.13.0, which was released August 10th, 2020.
|
|
// https://www.hashicorp.com/blog/announcing-hashicorp-terraform-0-13
|
|
minimumTerraformVersion = func() *version.Version {
|
|
v, err := version.NewSemver("0.13.0")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}()
|
|
)
|
|
|
|
type ServeOptions struct {
|
|
*provisionersdk.ServeOptions
|
|
|
|
// BinaryPath specifies the "terraform" binary to use.
|
|
// If omitted, the $PATH will attempt to find it.
|
|
BinaryPath string
|
|
}
|
|
|
|
// Serve starts a dRPC server on the provided transport speaking Terraform provisioner.
|
|
func Serve(ctx context.Context, options *ServeOptions) error {
|
|
if options.BinaryPath == "" {
|
|
binaryPath, err := exec.LookPath("terraform")
|
|
if err != nil {
|
|
return xerrors.Errorf("terraform binary not found: %w", err)
|
|
}
|
|
options.BinaryPath = binaryPath
|
|
}
|
|
|
|
return provisionersdk.Serve(ctx, &terraform{
|
|
binaryPath: options.BinaryPath,
|
|
}, options.ServeOptions)
|
|
}
|
|
|
|
type terraform struct {
|
|
binaryPath string
|
|
}
|