mirror of https://github.com/hashicorp/terraform
parent
66fdd196f1
commit
5ef646e072
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/builtin/providers/influxdb"
|
||||
"github.com/hashicorp/terraform/plugin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
plugin.Serve(&plugin.ServeOpts{
|
||||
ProviderFunc: influxdb.Provider,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
package main
|
||||
@ -0,0 +1,72 @@
|
||||
package influxdb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/influxdb/influxdb/client"
|
||||
)
|
||||
|
||||
var quoteReplacer = strings.NewReplacer(`"`, `\"`)
|
||||
|
||||
// Provider returns a terraform.ResourceProvider.
|
||||
func Provider() terraform.ResourceProvider {
|
||||
return &schema.Provider{
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"url": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc(
|
||||
"INFLUXDB_URL", "http://localhost:8086/",
|
||||
),
|
||||
},
|
||||
"username": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("INFLUXDB_USERNAME", ""),
|
||||
},
|
||||
"password": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("INFLUXDB_PASSWORD", ""),
|
||||
},
|
||||
},
|
||||
|
||||
ConfigureFunc: Configure,
|
||||
}
|
||||
}
|
||||
|
||||
func Configure(d *schema.ResourceData) (interface{}, error) {
|
||||
url, err := url.Parse(d.Get("url").(string))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid InfluxDB URL: %s", err)
|
||||
}
|
||||
|
||||
config := client.Config{
|
||||
URL: *url,
|
||||
Username: d.Get("username").(string),
|
||||
Password: d.Get("password").(string),
|
||||
}
|
||||
|
||||
conn, err := client.NewClient(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, _, err = conn.Ping()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error pinging server: %s", err)
|
||||
}
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func quoteIdentifier(ident string) string {
|
||||
return fmt.Sprintf(`"%s"`, quoteReplacer.Replace(ident))
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package influxdb
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
// To run these acceptance tests, you will need an InfluxDB server.
|
||||
// If you download an InfluxDB distribution and run it with its default
|
||||
// settings, on the same host where the tests are being run, then these tests
|
||||
// should work with no further configuration.
|
||||
//
|
||||
// To run the tests against a remote InfluxDB server, set the INFLUXDB_URL,
|
||||
// INFLUXDB_USERNAME and INFLUXDB_PASSWORD environment variables.
|
||||
|
||||
var testAccProviders map[string]terraform.ResourceProvider
|
||||
var testAccProvider *schema.Provider
|
||||
|
||||
func init() {
|
||||
testAccProvider = Provider().(*schema.Provider)
|
||||
testAccProviders = map[string]terraform.ResourceProvider{
|
||||
"influxdb": 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()
|
||||
}
|
||||
Loading…
Reference in new issue