diff --git a/Makefile b/Makefile index 1e15404..98f6824 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,8 @@ xcompile: @rm -rf build/ @mkdir -p build gox \ - -os="darwin" \ + -osarch="darwin/386" \ + -osarch="darwin/amd64" \ -os="linux" \ -output="build/$(BINARY)_$(VERSION)_{{.OS}}_{{.Arch}}/$(BINARY)-{{.Dir}}" $$(glide nv) # -os="freebsd" \ diff --git a/README.md b/README.md index f8686de..801654c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,22 @@ Terraform provisioner for Converge +This plugin allows you to run converge directly in terraform. + +## Installing + +Download a binary from the [releases page](https://github.com/asteris-llc/terraform-provisioner-converge/releases). + +Then create a `.terraformrc` file in your home directory with the `converge` provisioner +pointing to the location of your downloaded binary. + +```hcl +provisioners { + converge = "/usr/local/bin/terraform-provisioner-converge" +} +``` + + ## Building ```shell @@ -15,6 +31,8 @@ $ make * `ca_file` (optional) - Path to a CA certificate to trust. Requires `use_ssl` * `cert_file` (optional) - Path to a certificate file for SSL. Requires `use_ssl` * `download_binary` (optional) - Install Converge binary. Default to `false` +* `install_dir` (optional) - Directory to install converge binary on the remote host. Default is `/usr/bin` +* `binary_dir` (optional) - Location of the converge binary on the remote host. Default is `/usr/bin` * `key_file` (optional) - Path to a key file for SSL. Requires `use_ssl` * `local` (optional) - Run Converge in local mode. Defaults to `true` * `local_addr` (optional) - Address to use for local RPC connection diff --git a/converge/linux_provisioner.go b/converge/linux_provisioner.go index 8a77856..d2e977b 100644 --- a/converge/linux_provisioner.go +++ b/converge/linux_provisioner.go @@ -9,7 +9,7 @@ import ( ) const ( - binaryPath = "/usr/bin" + binaryDir = "/usr/bin" ) func (p *Provisioner) installConvergeBinary( @@ -33,10 +33,10 @@ func (p *Provisioner) installConvergeBinary( return err } - err = p.runCommand(o, comm, fmt.Sprintf("%ssh ./install.sh -v %q", prefix, p.Version)) + err = p.runCommand(o, comm, fmt.Sprintf("%ssh ./install-converge.sh -v %q -d %q", prefix, p.Version, p.InstallDir)) if err != nil { return err } - return p.runCommand(o, comm, fmt.Sprintf("%srm -f install.sh", prefix)) + return p.runCommand(o, comm, fmt.Sprintf("%srm -f install-converge.sh", prefix)) } diff --git a/converge/resource_provisioner.go b/converge/resource_provisioner.go index 38b9353..5767dd2 100644 --- a/converge/resource_provisioner.go +++ b/converge/resource_provisioner.go @@ -17,25 +17,28 @@ import ( ) const ( - installURL = "https://dl.bintray.com/chrisaubuchon/converge/install.sh" - defaultVersion = "latest" + installURL = "https://raw.githubusercontent.com/asteris-llc/converge/master/install-converge.sh" + defaultInstallDir = binaryDir + defaultVersion = "0.3.0-beta2" ) type Provisioner struct { - Download bool `mapstructure:"download_binary"` - CaFile string `mapstructure:"ca_file"` - CertFile string `mapstructure:"cert_file"` - KeyFile string `mapstructure:"key_file"` - Local bool `mapstructure:"local"` - LocalAddr string `mapstructure:"local_addr"` - LogLevel string `mapstructure:"log_level"` - Hcl []string `mapstructure:"hcl"` - NoToken bool `mapstructure:"no_token"` - Params map[string]interface{} `mapstructure:"params"` - RpcAddr string `mapstructure:"rpc_addr"` - RpcToken string `mapstructure:"rpc_token"` - UseSsl bool `mapstructure:"use_ssl"` - Version string `mapstructure:"version"` + Download bool `mapstructure:"download_binary"` + CaFile string `mapstructure:"ca_file"` + CertFile string `mapstructure:"cert_file"` + KeyFile string `mapstructure:"key_file"` + Local bool `mapstructure:"local"` + LocalAddr string `mapstructure:"local_addr"` + LogLevel string `mapstructure:"log_level"` + Hcl []string `mapstructure:"hcl"` + NoToken bool `mapstructure:"no_token"` + Params map[string]interface{} `mapstructure:"params"` + RpcAddr string `mapstructure:"rpc_addr"` + RpcToken string `mapstructure:"rpc_token"` + UseSsl bool `mapstructure:"use_ssl"` + Version string `mapstructure:"version"` + BinaryDir string `mapstructure:"binary_dir"` + InstallDir string `mapstructure:"install_dir"` HTTPProxy string `mapstructure:"http_proxy"` HTTPSProxy string `mapstructure:"https_proxy"` @@ -63,6 +66,13 @@ func (r *ResourceProvisioner) Apply( p.Version = defaultVersion } + if p.BinaryDir == "" { + p.BinaryDir = binaryDir + } + + if p.InstallDir == "" { + p.InstallDir = defaultInstallDir + } // Get a new communicator comm, err := communicator.New(s) if err != nil { @@ -225,7 +235,7 @@ func (p *Provisioner) runConverge(o terraform.UIOutput, comm communicator.Commun } func (p *Provisioner) buildCommandLine() (string, error) { - cmd := bytes.NewBufferString(fmt.Sprintf("%s/converge apply", binaryPath)) + cmd := bytes.NewBufferString(fmt.Sprintf("%s/converge apply", p.BinaryDir)) // An RPC address takes precedence over a local address if p.RpcAddr != "" { diff --git a/converge/resource_provisioner_test.go b/converge/resource_provisioner_test.go index 86cb7ef..5950867 100644 --- a/converge/resource_provisioner_test.go +++ b/converge/resource_provisioner_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" ) -func test_makeCommand(s string) string { +func testMakeCommand(s string) string { return fmt.Sprintf("%s/converge apply %s ", binaryPath, s) } @@ -17,20 +17,20 @@ func TestBuildCommandLine(t *testing.T) { // Basic test. --local is the default so it is expected cmd, err := p.buildCommandLine() assert.Nil(t, err) - assert.Equal(t, test_makeCommand("--local"), cmd) + assert.Equal(t, testMakeCommand("--local"), cmd) // Local addr test p.LocalAddr = "1.2.3.4:5678" cmd, err = p.buildCommandLine() assert.Nil(t, err) - assert.Equal(t, test_makeCommand("--local --local-addr='1.2.3.4:5678'"), cmd) + assert.Equal(t, testMakeCommand("--local --local-addr='1.2.3.4:5678'"), cmd) // RPC addr test. Leave Local and LocalAddr set to verify that they are not set // in the final command line p.RpcAddr = "8.7.6.5:4321" cmd, err = p.buildCommandLine() assert.Nil(t, err) - assert.Equal(t, test_makeCommand("--rpc-addr='8.7.6.5:4321'"), cmd) + assert.Equal(t, testMakeCommand("--rpc-addr='8.7.6.5:4321'"), cmd) // Clear RPC addr. --local is expected in the following tests p.RpcAddr = "" @@ -41,14 +41,14 @@ func TestBuildCommandLine(t *testing.T) { p.NoToken = true cmd, err = p.buildCommandLine() assert.Nil(t, err) - assert.Equal(t, test_makeCommand("--local --no-token"), cmd) + assert.Equal(t, testMakeCommand("--local --no-token"), cmd) p.NoToken = false // RpcToken p.RpcToken = "1234" cmd, err = p.buildCommandLine() assert.Nil(t, err) - assert.Equal(t, test_makeCommand("--local --rpc-token='1234'"), cmd) + assert.Equal(t, testMakeCommand("--local --rpc-token='1234'"), cmd) p.RpcToken = "" p.UseSsl = false @@ -59,19 +59,19 @@ func TestBuildCommandLine(t *testing.T) { p.KeyFile = "key_file" cmd, err = p.buildCommandLine() assert.Nil(t, err) - assert.Equal(t, test_makeCommand("--local"), cmd) + assert.Equal(t, testMakeCommand("--local"), cmd) // UseSsl p.UseSsl = true cmd, err = p.buildCommandLine() assert.Nil(t, err) - assert.Equal(t, test_makeCommand("--local --use-ssl --ca-file='ca_file' --cert-file='cert_file' --key-file='key_file'"), cmd) + assert.Equal(t, testMakeCommand("--local --use-ssl --ca-file='ca_file' --cert-file='cert_file' --key-file='key_file'"), cmd) p.UseSsl = false // Params p.Params = map[string]interface{}{"test": "tset"} cmd, err = p.buildCommandLine() assert.Nil(t, err) - assert.Equal(t, test_makeCommand("--local --paramsJSON='{\"test\":\"tset\"}'"), cmd) + assert.Equal(t, testMakeCommand("--local --paramsJSON='{\"test\":\"tset\"}'"), cmd) p.Params = nil } diff --git a/main.go b/main.go index 5adce4c..8ed4008 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,14 @@ package main import ( - "github.com/ChrisAubuchon/terraform-provisioner-converge/converge" + "github.com/asteris-llc/terraform-provisioner-converge/converge" "github.com/hashicorp/terraform/plugin" "github.com/hashicorp/terraform/terraform" ) const Name = "terraform-provisioner-converge" -const Version = "0.1.0" +const Version = "0.2.0-beta1" func main() { plugin.Serve(&plugin.ServeOpts{