diff --git a/builtin/bins/provider-null/main.go b/builtin/bins/provider-null/main.go new file mode 100644 index 000000000..04e266ffd --- /dev/null +++ b/builtin/bins/provider-null/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/hashicorp/terraform/builtin/providers/null" + "github.com/hashicorp/terraform/plugin" + "github.com/hashicorp/terraform/terraform" +) + +func main() { + plugin.Serve(&plugin.ServeOpts{ + ProviderFunc: func() terraform.ResourceProvider { + return null.Provider() + }, + }) +} diff --git a/builtin/bins/provider-null/main_test.go b/builtin/bins/provider-null/main_test.go new file mode 100644 index 000000000..06ab7d0f9 --- /dev/null +++ b/builtin/bins/provider-null/main_test.go @@ -0,0 +1 @@ +package main diff --git a/builtin/providers/null/provider.go b/builtin/providers/null/provider.go new file mode 100644 index 000000000..7e2a70c6c --- /dev/null +++ b/builtin/providers/null/provider.go @@ -0,0 +1,17 @@ +package null + +import ( + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/terraform" +) + +// Provider returns a terraform.ResourceProvider. +func Provider() terraform.ResourceProvider { + return &schema.Provider{ + Schema: map[string]*schema.Schema{}, + + ResourcesMap: map[string]*schema.Resource{ + "null_resource": resource(), + }, + } +} diff --git a/builtin/providers/null/provider_test.go b/builtin/providers/null/provider_test.go new file mode 100644 index 000000000..2cb1bb6ca --- /dev/null +++ b/builtin/providers/null/provider_test.go @@ -0,0 +1,18 @@ +package null + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/terraform" +) + +func TestProvider(t *testing.T) { + if err := Provider().(*schema.Provider).InternalValidate(); err != nil { + t.Fatalf("err: %s", err) + } +} + +func TestProvider_impl(t *testing.T) { + var _ terraform.ResourceProvider = Provider() +} diff --git a/builtin/providers/null/resource.go b/builtin/providers/null/resource.go new file mode 100644 index 000000000..0badf346c --- /dev/null +++ b/builtin/providers/null/resource.go @@ -0,0 +1,42 @@ +package null + +import ( + "fmt" + "math/rand" + "time" + + "github.com/hashicorp/terraform/helper/schema" +) + +func init() { + rand.Seed(time.Now().Unix()) +} + +func resource() *schema.Resource { + return &schema.Resource{ + Create: resourceCreate, + Read: resourceRead, + Update: resourceUpdate, + Delete: resourceDelete, + + Schema: map[string]*schema.Schema{}, + } +} + +func resourceCreate(d *schema.ResourceData, meta interface{}) error { + d.SetId(fmt.Sprintf("%d", rand.Int())) + return nil +} + +func resourceRead(d *schema.ResourceData, meta interface{}) error { + return nil +} + +func resourceUpdate(d *schema.ResourceData, meta interface{}) error { + return nil +} + +func resourceDelete(d *schema.ResourceData, meta interface{}) error { + d.SetId("") + return nil +} diff --git a/terraform/context.go b/terraform/context.go index 132a9f48d..146152a0e 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -634,13 +634,12 @@ func (c *walkContext) applyWalkFn() depgraph.WalkFunc { return err } - // This should never happen because we check if Diff.Empty above. - // If this happened, then the diff above returned a bad diff. + // This can happen if we aren't actually applying anything + // except an ID (the "null" provider). It is not really an issue + // since the Same check later down will catch any real problems. if diff == nil { - return fmt.Errorf( - "%s: diff became nil during Apply. This is a bug with "+ - "the resource provider. Please report a bug.", - r.Id) + diff = new(InstanceDiff) + diff.init() } // Delete id from the diff because it is dependent on