Merge pull request #362 from hashicorp/f-dummy-provider
Add a "null" provider
This commit is contained in:
commit
8de7f19901
|
@ -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()
|
||||
},
|
||||
})
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
package main
|
|
@ -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(),
|
||||
},
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue