From 6381fbd226275d3666142c6c232cc31d5d96347c Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 10 Jul 2014 13:30:44 -0700 Subject: [PATCH] provisioner/remote-exec: Adding initial skeleton --- builtin/bins/provisioner-remote-exec/main.go | 10 ++++ .../bins/provisioner-remote-exec/main_test.go | 1 + .../remote-exec/resource_provisioner.go | 25 +++++++++ .../remote-exec/resource_provisioner_test.go | 51 +++++++++++++++++++ config.go | 3 +- 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 builtin/bins/provisioner-remote-exec/main.go create mode 100644 builtin/bins/provisioner-remote-exec/main_test.go create mode 100644 builtin/provisioners/remote-exec/resource_provisioner.go create mode 100644 builtin/provisioners/remote-exec/resource_provisioner_test.go diff --git a/builtin/bins/provisioner-remote-exec/main.go b/builtin/bins/provisioner-remote-exec/main.go new file mode 100644 index 000000000..b7b2c53b4 --- /dev/null +++ b/builtin/bins/provisioner-remote-exec/main.go @@ -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)) +} diff --git a/builtin/bins/provisioner-remote-exec/main_test.go b/builtin/bins/provisioner-remote-exec/main_test.go new file mode 100644 index 000000000..06ab7d0f9 --- /dev/null +++ b/builtin/bins/provisioner-remote-exec/main_test.go @@ -0,0 +1 @@ +package main diff --git a/builtin/provisioners/remote-exec/resource_provisioner.go b/builtin/provisioners/remote-exec/resource_provisioner.go new file mode 100644 index 000000000..5a9834c10 --- /dev/null +++ b/builtin/provisioners/remote-exec/resource_provisioner.go @@ -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) +} diff --git a/builtin/provisioners/remote-exec/resource_provisioner_test.go b/builtin/provisioners/remote-exec/resource_provisioner_test.go new file mode 100644 index 000000000..2d09fea0b --- /dev/null +++ b/builtin/provisioners/remote-exec/resource_provisioner_test.go @@ -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) +} diff --git a/config.go b/config.go index b616414d7..77bf01a07 100644 --- a/config.go +++ b/config.go @@ -36,7 +36,8 @@ func init() { "aws": "terraform-provider-aws", } BuiltinConfig.Provisioners = map[string]string{ - "local-exec": "terraform-provisioner-local-exec", + "local-exec": "terraform-provisioner-local-exec", + "remote-exec": "terraform-provisioner-remote-exec", } }