Skip to content

Commit

Permalink
Use function_schema instead of schema and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabianoshz committed Oct 16, 2024
1 parent f772fb2 commit d6dba90
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
13 changes: 6 additions & 7 deletions postgresql/resource_postgresql_event_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const (
eventTriggerNameAttr = "name"
eventTriggerOnAttr = "on"
eventTriggerFunctionAttr = "function"
eventTriggerFunctionSchemaAttr = "function_schema"
eventTriggerFilterAttr = "filter"
eventTriggerFilterVariableAttr = "variable"
eventTriggerFilterValueAttr = "values"
eventTriggerDatabaseAttr = "database"
eventTriggerSchemaAttr = "schema"
eventTriggerOwnerAttr = "owner"
eventTriggerStatusAttr = "status"
)
Expand Down Expand Up @@ -95,12 +95,11 @@ func resourcePostgreSQLEventTrigger() *schema.Resource {
ForceNew: true,
Description: "The database where the event trigger is located. If not specified, the provider default database is used.",
},
eventTriggerSchemaAttr: {
eventTriggerFunctionSchemaAttr: {
Type: schema.TypeString,
Optional: true,
Computed: true,
Required: true,
ForceNew: true,
Description: "Schema where the function is located. If not specified, the provider default schema is used.",
Description: "Schema where the function is located.",
},
eventTriggerStatusAttr: {
Type: schema.TypeString,
Expand Down Expand Up @@ -165,7 +164,7 @@ func resourcePostgreSQLEventTriggerCreate(db *DBConnection, d *schema.ResourceDa
}

eventTriggerFunction := d.Get(eventTriggerFunctionAttr).(string)
eventTriggerSchema := d.Get(eventTriggerSchemaAttr).(string)
eventTriggerSchema := d.Get(eventTriggerFunctionSchemaAttr).(string)
fmt.Fprint(b, " EXECUTE FUNCTION ", pq.QuoteIdentifier(eventTriggerSchema), ".", eventTriggerFunction, "()")

createSql := b.String()
Expand Down Expand Up @@ -330,7 +329,7 @@ func resourcePostgreSQLEventTriggerRead(db *DBConnection, d *schema.ResourceData
d.Set(eventTriggerFunctionAttr, function)
d.Set(eventTriggerOwnerAttr, owner)
d.Set(eventTriggerDatabaseAttr, database)
d.Set(eventTriggerSchemaAttr, schema)
d.Set(eventTriggerFunctionSchemaAttr, schema)

switch status {
case "D":
Expand Down
5 changes: 4 additions & 1 deletion postgresql/resource_postgresql_event_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
)

func TestAccPostgresqlEventTrigger_Basic(t *testing.T) {
skipIfNotAcc(t)
testSuperuserPreCheck(t)

// Create the database outside of resource.Test
// because we need to create test schemas.
dbSuffix, teardown := setupTestDatabase(t, true, true)
Expand Down Expand Up @@ -135,8 +138,8 @@ resource "postgresql_function" "function" {
resource "postgresql_event_trigger" "event_trigger" {
name = "event_trigger_test"
database = "%[1]s"
schema = "%[2]s"
function = postgresql_function.function.name
function_schema = postgresql_function.function.schema
on = "ddl_command_end"
owner = "postgres"
status = "enable"
Expand Down
16 changes: 8 additions & 8 deletions website/docs/r/postgresql_event_trigger.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ resource "postgresql_function" "function" {
}
resource "postgresql_event_trigger" "event_trigger" {
name = "event_trigger_test"
function = postgresql_function.function.name
on = "ddl_command_start"
owner = "postgres"
name = "event_trigger_test"
function = postgresql_function.function.name
function_schema = postgresql_function.function.schema
on = "ddl_command_start"
owner = "postgres"
filter {
variable = "TAG"
Expand All @@ -50,16 +51,15 @@ resource "postgresql_event_trigger" "event_trigger" {

* `function` - (Required) A function that is declared as taking no argument and returning type event_trigger.

* `function_schema` - (Required) Schema where the function is located.

* `filter` - (Optional) Lists of filter variables to restrict the firing of the trigger. Currently the only supported filter_variable is TAG.
* `variable` - (Required) The name of a variable used to filter events. Currently the only supported value is TAG.
* `values` - (Required) The name of the filter variable name. For TAG, this means a list of command tags (e.g., 'DROP FUNCTION').

* `database` - (Optional) The database where the event trigger is located.
If not specified, the function is created in the current database.

* `schema` - (Optional) Schema where the function is located.
If not specified, the function is created in the current schema.

* `status` - (Optional) These configure the firing of event triggers. The allowed names are "disable", "enable", "enable_replica" or "enable_always". Default is "enable".

* `owner` - (Required) The user name of the owner of the event trigger. You can't use 'current_role', 'current_user' or 'session_user' in order to avoid drifts.
Expand All @@ -71,4 +71,4 @@ command:

```
$ terraform import postgresql_event_trigger.event_trigger_test "database.event_trigger"
```
```

0 comments on commit d6dba90

Please sign in to comment.