Update based off review
This commit is contained in:
parent
792a6c0232
commit
5dbd9423cc
|
@ -45,6 +45,7 @@ func Provider() terraform.ResourceProvider {
|
||||||
ResourcesMap: map[string]*schema.Resource{
|
ResourcesMap: map[string]*schema.Resource{
|
||||||
"postgresql_database": resourcePostgreSQLDatabase(),
|
"postgresql_database": resourcePostgreSQLDatabase(),
|
||||||
"postgresql_role": resourcePostgreSQLRole(),
|
"postgresql_role": resourcePostgreSQLRole(),
|
||||||
|
"postgresql_extension": resourcePostgreSQLExtension(),
|
||||||
},
|
},
|
||||||
|
|
||||||
ConfigureFunc: providerConfigure,
|
ConfigureFunc: providerConfigure,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package postgresql
|
package postgresql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/errwrap"
|
"github.com/hashicorp/errwrap"
|
||||||
|
@ -11,6 +12,7 @@ import (
|
||||||
func resourcePostgreSQLExtension() *schema.Resource {
|
func resourcePostgreSQLExtension() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Create: resourcePostgreSQLExtensionCreate,
|
Create: resourcePostgreSQLExtensionCreate,
|
||||||
|
Read: resourcePostgreSQLExtensionRead,
|
||||||
Delete: resourcePostgreSQLExtensionDelete,
|
Delete: resourcePostgreSQLExtensionDelete,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
@ -41,7 +43,31 @@ func resourcePostgreSQLExtensionCreate(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
d.SetId(extensionName)
|
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 {
|
func resourcePostgreSQLExtensionDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
<li<%= sidebar_current("docs-postgresql-resource-postgresql_role") %>>
|
<li<%= sidebar_current("docs-postgresql-resource-postgresql_role") %>>
|
||||||
<a href="/docs/providers/postgresql/r/postgresql_role.html">postgresql_role</a>
|
<a href="/docs/providers/postgresql/r/postgresql_role.html">postgresql_role</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li<%= sidebar_current("docs-postgresql-resource-postgresql_extension") %>>
|
||||||
|
<a href="/docs/providers/postgresql/r/postgresql_extension.html">postgresql_extensions</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in New Issue