provider/postgres: Use standard environment vars

Previously the provider accepted non-standard environment variables. We
now accept the standard PGHOST/PGUSER/PGPASSWORD variables that psql
uses in addition the older ones.
This commit is contained in:
James Nugent 2016-09-05 15:04:08 -07:00
parent 260179543a
commit 006ab910b8
1 changed files with 11 additions and 11 deletions

View File

@ -13,38 +13,38 @@ func Provider() terraform.ResourceProvider {
"host": { "host": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
DefaultFunc: schema.EnvDefaultFunc("POSTGRESQL_HOST", nil), DefaultFunc: schema.MultiEnvDefaultFunc([]string{"PGUSER", "POSTGRESQL_HOST"}, nil),
Description: "The postgresql server address", Description: "The PostgreSQL server address",
}, },
"port": { "port": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Default: 5432, Default: 5432,
Description: "The postgresql server port", Description: "The PostgreSQL server port",
}, },
"username": { "username": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
DefaultFunc: schema.EnvDefaultFunc("POSTGRESQL_USERNAME", nil), DefaultFunc: schema.MultiEnvDefaultFunc([]string{"PGHOST", "POSTGRESQL_HOST"}, nil),
Description: "Username for postgresql server connection", Description: "Username for PostgreSQL server connection",
}, },
"password": { "password": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
DefaultFunc: schema.EnvDefaultFunc("POSTGRESQL_PASSWORD", nil), DefaultFunc: schema.MultiEnvDefaultFunc([]string{"PGPASSWORD", "POSTGRESQL_PASSWORD"}, nil),
Description: "Password for postgresql server connection", Description: "Password for PostgreSQL server connection",
}, },
"ssl_mode": { "ssl_mode": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Default: "prefer", Default: "prefer",
Description: "Connection mode for postgresql server", Description: "Connection mode for PostgreSQL server",
}, },
}, },
ResourcesMap: map[string]*schema.Resource{ ResourcesMap: map[string]*schema.Resource{
"postgresql_database": resourcePostgresqlDatabase(), "postgresql_database": resourcePostgreSQLDatabase(),
"postgresql_role": resourcePostgresqlRole(), "postgresql_role": resourcePostgreSQLRole(),
}, },
ConfigureFunc: providerConfigure, ConfigureFunc: providerConfigure,
@ -62,7 +62,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
client, err := config.NewClient() client, err := config.NewClient()
if err != nil { if err != nil {
return nil, errwrap.Wrapf("Error initializing Postgresql client: %s", err) return nil, errwrap.Wrapf("Error initializing PostgreSQL client: %s", err)
} }
return client, nil return client, nil