provisioner/remote-exec: Adding initial skeleton

This commit is contained in:
Armon Dadgar 2014-07-10 13:30:44 -07:00
parent 1d6dc475df
commit 6381fbd226
5 changed files with 89 additions and 1 deletions

View File

@ -0,0 +1,10 @@
package main
import (
"github.com/hashicorp/terraform/builtin/provisioners/remote-exec"
"github.com/hashicorp/terraform/plugin"
)
func main() {
plugin.Serve(new(remoteexec.ResourceProvisioner))
}

View File

@ -0,0 +1 @@
package main

View File

@ -0,0 +1,25 @@
package remoteexec
import (
"github.com/hashicorp/terraform/helper/config"
"github.com/hashicorp/terraform/terraform"
)
type ResourceProvisioner struct{}
func (p *ResourceProvisioner) Apply(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceState, error) {
panic("not implemented")
return s, nil
}
func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) ([]string, []error) {
validator := config.Validator{
Optional: []string{
"command",
"inline",
},
}
return validator.Validate(c)
}

View File

@ -0,0 +1,51 @@
package remoteexec
import (
"testing"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/terraform"
)
func TestResourceProvisioner_impl(t *testing.T) {
var _ terraform.ResourceProvisioner = new(ResourceProvisioner)
}
func TestResourceProvider_Validate_good(t *testing.T) {
c := testConfig(t, map[string]interface{}{
"command": "echo foo",
})
p := new(ResourceProvisioner)
warn, errs := p.Validate(c)
if len(warn) > 0 {
t.Fatalf("Warnings: %v", warn)
}
if len(errs) > 0 {
t.Fatalf("Errors: %v", errs)
}
}
func TestResourceProvider_Validate_bad(t *testing.T) {
c := testConfig(t, map[string]interface{}{
"invalid": "nope",
})
p := new(ResourceProvisioner)
warn, errs := p.Validate(c)
if len(warn) > 0 {
t.Fatalf("Warnings: %v", warn)
}
if len(errs) == 0 {
t.Fatalf("Should have errors")
}
}
func testConfig(
t *testing.T,
c map[string]interface{}) *terraform.ResourceConfig {
r, err := config.NewRawConfig(c)
if err != nil {
t.Fatalf("bad: %s", err)
}
return terraform.NewResourceConfig(r)
}

View File

@ -37,6 +37,7 @@ func init() {
}
BuiltinConfig.Provisioners = map[string]string{
"local-exec": "terraform-provisioner-local-exec",
"remote-exec": "terraform-provisioner-remote-exec",
}
}