Update based off review

This commit is contained in:
Sam Dunne 2016-11-02 14:36:39 +00:00
parent 792a6c0232
commit 5dbd9423cc
No known key found for this signature in database
GPG Key ID: B9754C0CCECB63CB
3 changed files with 31 additions and 1 deletions

View File

@ -45,6 +45,7 @@ func Provider() terraform.ResourceProvider {
ResourcesMap: map[string]*schema.Resource{
"postgresql_database": resourcePostgreSQLDatabase(),
"postgresql_role": resourcePostgreSQLRole(),
"postgresql_extension": resourcePostgreSQLExtension(),
},
ConfigureFunc: providerConfigure,

View File

@ -1,6 +1,7 @@
package postgresql
import (
"database/sql"
"fmt"
"github.com/hashicorp/errwrap"
@ -11,6 +12,7 @@ import (
func resourcePostgreSQLExtension() *schema.Resource {
return &schema.Resource{
Create: resourcePostgreSQLExtensionCreate,
Read: resourcePostgreSQLExtensionRead,
Delete: resourcePostgreSQLExtensionDelete,
Schema: map[string]*schema.Schema{
@ -41,7 +43,31 @@ func resourcePostgreSQLExtensionCreate(d *schema.ResourceData, meta interface{})
d.SetId(extensionName)
return resourcePostgreSQLRoleRead(d, meta)
return resourcePostgreSQLExtensionRead(d, meta)
}
func resourcePostgreSQLExtensionRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client)
conn, err := client.Connect()
if err != nil {
return err
}
defer conn.Close()
extensionName := d.Get("name").(string)
var hasExtension bool
err = conn.QueryRow("SELECT 1 from pg_extension d WHERE extname=$1", extensionName).Scan(&hasExtension)
switch {
case err == sql.ErrNoRows:
d.SetId("")
return nil
case err != nil:
return errwrap.Wrapf("Error reading extension: {{err}}", err)
default:
d.Set("extension", hasExtension)
return nil
}
}
func resourcePostgreSQLExtensionDelete(d *schema.ResourceData, meta interface{}) error {

View File

@ -19,6 +19,9 @@
<li<%= sidebar_current("docs-postgresql-resource-postgresql_role") %>>
<a href="/docs/providers/postgresql/r/postgresql_role.html">postgresql_role</a>
</li>
<li<%= sidebar_current("docs-postgresql-resource-postgresql_extension") %>>
<a href="/docs/providers/postgresql/r/postgresql_extension.html">postgresql_extensions</a>
</li>
</ul>
</li>
</ul>