Skip to content

Commit

Permalink
Merge pull request #5814 from hashicorp/provider-fastly-v1
Browse files Browse the repository at this point in the history
provider/fastly: V1 of the Fastly Provider
  • Loading branch information
catsby committed Mar 24, 2016
2 parents b20f680 + e8f2afb commit c9293cc
Show file tree
Hide file tree
Showing 59 changed files with 9,082 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions builtin/bins/provider-fastly/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"github.com/hashicorp/terraform/builtin/providers/fastly"
"github.com/hashicorp/terraform/plugin"
)

func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: fastly.Provider,
})
}
1 change: 1 addition & 0 deletions builtin/bins/provider-fastly/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
31 changes: 31 additions & 0 deletions builtin/providers/fastly/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fastly

import (
"fmt"

gofastly "github.com/sethvargo/go-fastly"
)

type Config struct {
ApiKey string
}

type FastlyClient struct {
conn *gofastly.Client
}

func (c *Config) Client() (interface{}, error) {
var client FastlyClient

if c.ApiKey == "" {
return nil, fmt.Errorf("[Err] No API key for Fastly")
}

fconn, err := gofastly.NewClient(c.ApiKey)
if err != nil {
return nil, err
}

client.conn = fconn
return &client, nil
}
34 changes: 34 additions & 0 deletions builtin/providers/fastly/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fastly

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{
"api_key": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"FASTLY_API_KEY",
}, nil),
Description: "Fastly API Key from https://app.fastly.com/#account",
},
},
ResourcesMap: map[string]*schema.Resource{
"fastly_service_v1": resourceServiceV1(),
},

ConfigureFunc: providerConfigure,
}
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
ApiKey: d.Get("api_key").(string),
}
return config.Client()
}
35 changes: 35 additions & 0 deletions builtin/providers/fastly/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fastly

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{
"fastly": 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("FASTLY_API_KEY"); v == "" {
t.Fatal("FASTLY_API_KEY must be set for acceptance tests")
}
}
Loading

0 comments on commit c9293cc

Please sign in to comment.