From d26f5f93e481635dbe42398b8a5c952ed0fa3954 Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 28 Sep 2015 11:39:32 +0100 Subject: [PATCH] Created the initial scaffolding for the statuscake provider --- builtin/bins/provider-statuscake/main.go | 12 ++++++ builtin/providers/statuscake/provider.go | 39 +++++++++++++++++++ builtin/providers/statuscake/provider_test.go | 38 ++++++++++++++++++ .../statuscake/resource_statuscaketest.go | 28 +++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 builtin/bins/provider-statuscake/main.go create mode 100644 builtin/providers/statuscake/provider.go create mode 100644 builtin/providers/statuscake/provider_test.go create mode 100644 builtin/providers/statuscake/resource_statuscaketest.go diff --git a/builtin/bins/provider-statuscake/main.go b/builtin/bins/provider-statuscake/main.go new file mode 100644 index 000000000..9db330f00 --- /dev/null +++ b/builtin/bins/provider-statuscake/main.go @@ -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, + }) +} diff --git a/builtin/providers/statuscake/provider.go b/builtin/providers/statuscake/provider.go new file mode 100644 index 000000000..7402e8079 --- /dev/null +++ b/builtin/providers/statuscake/provider.go @@ -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 +} diff --git a/builtin/providers/statuscake/provider_test.go b/builtin/providers/statuscake/provider_test.go new file mode 100644 index 000000000..83045d06f --- /dev/null +++ b/builtin/providers/statuscake/provider_test.go @@ -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") + } +} diff --git a/builtin/providers/statuscake/resource_statuscaketest.go b/builtin/providers/statuscake/resource_statuscaketest.go new file mode 100644 index 000000000..f34a97a71 --- /dev/null +++ b/builtin/providers/statuscake/resource_statuscaketest.go @@ -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 +}