-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a Arukas provider * Add dependencies for the Arukas provider * Add documents for the Arukas
- Loading branch information
1 parent
08728d9
commit 9176bd4
Showing
79 changed files
with
13,141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
Oops, something went wrong.