Skip to content

Commit

Permalink
New provider arukas (#11171)
Browse files Browse the repository at this point in the history
* Add a Arukas provider

* Add dependencies for the Arukas provider

* Add documents for the Arukas
  • Loading branch information
yamamoto-febc authored and stack72 committed Feb 13, 2017
1 parent 647df14 commit d94ed4b
Show file tree
Hide file tree
Showing 40 changed files with 3,490 additions and 0 deletions.
12 changes: 12 additions & 0 deletions builtin/bins/provider-arukas/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/arukas"
"github.com/hashicorp/terraform/plugin"
)

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

import (
API "github.com/arukasio/cli"
"os"
"time"
)

const (
JSONTokenParamName = "ARUKAS_JSON_API_TOKEN"
JSONSecretParamName = "ARUKAS_JSON_API_SECRET"
JSONUrlParamName = "ARUKAS_JSON_API_URL"
JSONDebugParamName = "ARUKAS_DEBUG"
JSONTimeoutParamName = "ARUKAS_TIMEOUT"
)

type Config struct {
Token string
Secret string
URL string
Trace string
Timeout int
}

func (c *Config) NewClient() (*ArukasClient, error) {

os.Setenv(JSONTokenParamName, c.Token)
os.Setenv(JSONSecretParamName, c.Secret)
os.Setenv(JSONUrlParamName, c.URL)
os.Setenv(JSONDebugParamName, c.Trace)

client, err := API.NewClient()
if err != nil {
return nil, err
}
client.UserAgent = "Terraform for Arukas"

timeout := time.Duration(0)
if c.Timeout > 0 {
timeout = time.Duration(c.Timeout) * time.Second
}

return &ArukasClient{
Client: client,
Timeout: timeout,
}, nil
}

type ArukasClient struct {
*API.Client
Timeout time.Duration
}
59 changes: 59 additions & 0 deletions builtin/providers/arukas/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package arukas

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{
"token": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc(JSONTokenParamName, nil),
Description: "your Arukas APIKey(token)",
},
"secret": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc(JSONSecretParamName, nil),
Description: "your Arukas APIKey(secret)",
},
"api_url": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc(JSONUrlParamName, "https://app.arukas.io/api/"),
Description: "default Arukas API url",
},
"trace": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc(JSONDebugParamName, ""),
},
"timeout": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc(JSONTimeoutParamName, "600"),
},
},
ResourcesMap: map[string]*schema.Resource{
"arukas_container": resourceArukasContainer(),
},
ConfigureFunc: providerConfigure,
}
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {

config := Config{
Token: d.Get("token").(string),
Secret: d.Get("secret").(string),
URL: d.Get("api_url").(string),
Trace: d.Get("trace").(string),
Timeout: d.Get("timeout").(int),
}

return config.NewClient()
}
38 changes: 38 additions & 0 deletions builtin/providers/arukas/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package arukas

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{
"arukas": 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("ARUKAS_JSON_API_TOKEN"); v == "" {
t.Fatal("ARUKAS_JSON_API_TOKEN must be set for acceptance tests")
}
if v := os.Getenv("ARUKAS_JSON_API_SECRET"); v == "" {
t.Fatal("ARUKAS_JSON_API_SECRET must be set for acceptance tests")
}
}

0 comments on commit d94ed4b

Please sign in to comment.