Created the initial scaffolding for the statuscake provider

This commit is contained in:
stack72 2015-09-28 11:39:32 +01:00
parent a1d05e2a4c
commit d26f5f93e4
4 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package main
import (
"github.com/hashicorp/terraform/builtin/providers/statuscake"
"github.com/hashicorp/terraform/plugin"
)
func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: statuscake.Provider,
})
}

View File

@ -0,0 +1,39 @@
package statuscake
import (
"github.com/DreamItGetIT/statuscake"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"username": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("STATUSCAKE_USERNAME", nil),
Description: "Username for StatusCake Account.",
},
"apikey": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("STATUSCAKE_APIKEY", nil),
Description: "API Key for StatusCake",
},
},
ResourcesMap: map[string]*schema.Resource{
"statuscake_test": resourceStatusCakeTest(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
username := d.Get("username").(string)
apiKey := d.Get("apikey").(string)
return statuscake.New(apiKey, username), nil
}

View File

@ -0,0 +1,38 @@
package statuscake
import (
"os"
"testing"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider
func init() {
testAccProvider = Provider().(*schema.Provider)
testAccProviders = map[string]terraform.ResourceProvider{
"statuscake": testAccProvider,
}
}
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()
}
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("STATUSCAKE_USERNAME"); v == "" {
t.Fatal("STATUSCAKE_USERNAME must be set for acceptance tests")
}
if v := os.Getenv("STATUSCAKE_APIKEY"); v == "" {
t.Fatal("STATUSCAKE_APIKEY must be set for acceptance tests")
}
}

View File

@ -0,0 +1,28 @@
package statuscake
import "github.com/hashicorp/terraform/helper/schema"
func resourceStatusCakeTest() *schema.Resource {
return &schema.Resource{
Create: CreateTest,
Update: UpdateTest,
Delete: DeleteTest,
Read: ReadTest,
}
}
func CreateTest(d *schema.ResourceData, meta interface{}) error {
return nil
}
func UpdateTest(d *schema.ResourceData, meta interface{}) error {
return nil
}
func DeleteTest(d *schema.ResourceData, meta interface{}) error {
return nil
}
func ReadTest(d *schema.ResourceData, meta interface{}) error {
return nil
}