2015-10-27 11:04:19 +01:00
|
|
|
package postgresql
|
|
|
|
|
|
|
|
import (
|
2016-09-05 23:46:40 +02:00
|
|
|
"github.com/hashicorp/errwrap"
|
2015-10-27 11:04:19 +01:00
|
|
|
"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{
|
2016-09-05 23:46:40 +02:00
|
|
|
"host": {
|
2015-10-27 11:04:19 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
2016-09-06 00:39:57 +02:00
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"PGHOST", "POSTGRESQL_HOST"}, nil),
|
2016-09-06 00:04:08 +02:00
|
|
|
Description: "The PostgreSQL server address",
|
2015-10-27 11:04:19 +01:00
|
|
|
},
|
2016-09-05 23:46:40 +02:00
|
|
|
"port": {
|
2015-10-27 11:04:19 +01:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Default: 5432,
|
2016-09-06 00:04:08 +02:00
|
|
|
Description: "The PostgreSQL server port",
|
2015-10-27 11:04:19 +01:00
|
|
|
},
|
2016-09-05 23:46:40 +02:00
|
|
|
"username": {
|
2015-10-27 11:04:19 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
2016-09-06 00:39:57 +02:00
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"PGUSER", "POSTGRESQL_USER"}, nil),
|
2016-09-06 00:04:08 +02:00
|
|
|
Description: "Username for PostgreSQL server connection",
|
2015-10-27 11:04:19 +01:00
|
|
|
},
|
2016-09-05 23:46:40 +02:00
|
|
|
"password": {
|
2015-10-27 11:04:19 +01:00
|
|
|
Type: schema.TypeString,
|
2016-09-06 00:39:57 +02:00
|
|
|
Optional: true,
|
2016-09-06 00:04:08 +02:00
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"PGPASSWORD", "POSTGRESQL_PASSWORD"}, nil),
|
|
|
|
Description: "Password for PostgreSQL server connection",
|
2015-10-27 11:04:19 +01:00
|
|
|
},
|
2016-09-05 23:46:40 +02:00
|
|
|
"ssl_mode": {
|
2016-04-04 17:40:28 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-09-06 00:39:57 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("PGSSLMODE", "require"),
|
2016-09-06 00:04:08 +02:00
|
|
|
Description: "Connection mode for PostgreSQL server",
|
2016-04-04 17:40:28 +02:00
|
|
|
},
|
2015-10-27 11:04:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2016-09-06 00:04:08 +02:00
|
|
|
"postgresql_database": resourcePostgreSQLDatabase(),
|
|
|
|
"postgresql_role": resourcePostgreSQLRole(),
|
2016-11-02 15:36:39 +01:00
|
|
|
"postgresql_extension": resourcePostgreSQLExtension(),
|
2015-10-27 11:04:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
|
|
|
Host: d.Get("host").(string),
|
|
|
|
Port: d.Get("port").(int),
|
|
|
|
Username: d.Get("username").(string),
|
|
|
|
Password: d.Get("password").(string),
|
2016-04-04 17:40:28 +02:00
|
|
|
SslMode: d.Get("ssl_mode").(string),
|
2015-10-27 11:04:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
client, err := config.NewClient()
|
|
|
|
if err != nil {
|
2016-09-06 00:04:08 +02:00
|
|
|
return nil, errwrap.Wrapf("Error initializing PostgreSQL client: %s", err)
|
2015-10-27 11:04:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|