Merge pull request #362 from hashicorp/f-dummy-provider

Add a "null" provider
This commit is contained in:
Mitchell Hashimoto 2014-10-05 08:29:10 -07:00
commit 8de7f19901
6 changed files with 98 additions and 6 deletions

View File

@ -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()
},
})
}

View File

@ -0,0 +1 @@
package main

View File

@ -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(),
},
}
}

View File

@ -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()
}

View File

@ -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
}

View File

@ -634,13 +634,12 @@ func (c *walkContext) applyWalkFn() depgraph.WalkFunc {
return err return err
} }
// This should never happen because we check if Diff.Empty above. // This can happen if we aren't actually applying anything
// If this happened, then the diff above returned a bad diff. // 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 { if diff == nil {
return fmt.Errorf( diff = new(InstanceDiff)
"%s: diff became nil during Apply. This is a bug with "+ diff.init()
"the resource provider. Please report a bug.",
r.Id)
} }
// Delete id from the diff because it is dependent on // Delete id from the diff because it is dependent on