From d6dba90c1b9cbde2486cf566165cb19e77128965 Mon Sep 17 00:00:00 2001 From: Fabiano Soares Honorato Date: Wed, 16 Oct 2024 17:44:15 -0300 Subject: [PATCH] Use function_schema instead of schema and fix tests --- postgresql/resource_postgresql_event_trigger.go | 13 ++++++------- .../resource_postgresql_event_trigger_test.go | 5 ++++- .../r/postgresql_event_trigger.html.markdown | 16 ++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/postgresql/resource_postgresql_event_trigger.go b/postgresql/resource_postgresql_event_trigger.go index 14ae259c..08c93f09 100644 --- a/postgresql/resource_postgresql_event_trigger.go +++ b/postgresql/resource_postgresql_event_trigger.go @@ -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" ) @@ -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, @@ -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() @@ -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": diff --git a/postgresql/resource_postgresql_event_trigger_test.go b/postgresql/resource_postgresql_event_trigger_test.go index a74ebe3e..30e3d94a 100644 --- a/postgresql/resource_postgresql_event_trigger_test.go +++ b/postgresql/resource_postgresql_event_trigger_test.go @@ -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) @@ -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" diff --git a/website/docs/r/postgresql_event_trigger.html.markdown b/website/docs/r/postgresql_event_trigger.html.markdown index 0b7c5970..f736be62 100644 --- a/website/docs/r/postgresql_event_trigger.html.markdown +++ b/website/docs/r/postgresql_event_trigger.html.markdown @@ -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" @@ -50,6 +51,8 @@ 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'). @@ -57,9 +60,6 @@ resource "postgresql_event_trigger" "event_trigger" { * `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. @@ -71,4 +71,4 @@ command: ``` $ terraform import postgresql_event_trigger.event_trigger_test "database.event_trigger" -``` +``` \ No newline at end of file