Skip to content

Commit

Permalink
Merge pull request #1 from asteris-llc/feature/0.2.0-updates
Browse files Browse the repository at this point in the history
Feature/0.2.0 updates
  • Loading branch information
stevendborrelli authored Oct 25, 2016
2 parents c99e45d + 4991f5d commit a9e4e57
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 32 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions converge/linux_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
binaryPath = "/usr/bin"
binaryDir = "/usr/bin"
)

func (p *Provisioner) installConvergeBinary(
Expand All @@ -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))
}
44 changes: 27 additions & 17 deletions converge/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 != "" {
Expand Down
18 changes: 9 additions & 9 deletions converge/resource_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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 = ""
Expand All @@ -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
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -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{
Expand Down

0 comments on commit a9e4e57

Please sign in to comment.