Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/fastly: V1 of the Fastly Provider #5814

Merged
merged 4 commits into from
Mar 24, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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