providers/null: null provider

This commit is contained in:
Mitchell Hashimoto 2014-10-04 16:42:43 -07:00
parent a5f70ead2d
commit 5aa62ae635
5 changed files with 93 additions and 0 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
}