Skip to content

Commit

Permalink
fix realm event trigger issue (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
abner-dou authored Dec 10, 2021
1 parent 852006c commit e7d51c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion mongodbatlas/resource_mongodbatlas_event_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ func resourceMongoDBAtlasEventTriggersCreate(ctx context.Context, d *schema.Reso
if v, ok := d.GetOk("config_full_document"); ok {
eventTriggerConfig.FullDocument = pointy.Bool(v.(bool))
}
if v, ok := d.GetOk("config_full_document_before"); ok {
eventTriggerConfig.FullDocumentBeforeChange = pointy.Bool(v.(bool))
}
if oksch {
eventTriggerConfig.Schedule = sche.(string)
}
Expand Down Expand Up @@ -364,9 +367,11 @@ func resourceMongoDBAtlasEventTriggersRead(ctx context.Context, d *schema.Resour
if err = d.Set("config_full_document", resp.Config.FullDocument); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "config_full_document", projectID, appID, err))
}

if err = d.Set("config_full_document_before", resp.Config.FullDocumentBeforeChange); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "config_full_document_before", projectID, appID, err))
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "config_full_document", projectID, appID, err))
}

if err = d.Set("config_schedule", resp.Config.Schedule); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "config_schedule", projectID, appID, err))
}
Expand Down Expand Up @@ -411,6 +416,7 @@ func resourceMongoDBAtlasEventTriggersUpdate(ctx context.Context, d *schema.Reso
eventTriggerConfig.Match = cast.ToStringMap(d.Get("config_match").(string))
eventTriggerConfig.Project = cast.ToStringMap(d.Get("config_project").(string))
eventTriggerConfig.FullDocument = pointy.Bool(d.Get("config_full_document").(bool))
eventTriggerConfig.FullDocumentBeforeChange = pointy.Bool(d.Get("config_full_document_before").(bool))
}
if typeTrigger == "AUTHENTICATION" {
eventTriggerConfig.OperationType = d.Get("config_operation_type").(string)
Expand Down
11 changes: 6 additions & 5 deletions mongodbatlas/resource_mongodbatlas_event_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestAccResourceMongoDBAtlasEventTriggerDatabase_basic(t *testing.T) {
Database: "sample_airbnb",
Collection: "listingsAndReviews",
ServiceID: os.Getenv("MONGODB_REALM_SERVICE_ID"),
FullDocument: pointy.Bool(false),
},
}

Expand All @@ -55,14 +54,14 @@ func TestAccResourceMongoDBAtlasEventTriggerDatabase_basic(t *testing.T) {
CheckDestroy: testAccCheckMongoDBAtlasEventTriggerDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasEventTriggerDatabaseConfigDatabase(projectID, appID, `"INSERT", "UPDATE"`, &event),
Config: testAccMongoDBAtlasEventTriggerDatabaseConfigDatabase(projectID, appID, `"INSERT", "UPDATE"`, &event, false, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasEventTriggerExists(resourceName, &eventResp),
resource.TestCheckResourceAttr(resourceName, "project_id", projectID),
),
},
{
Config: testAccMongoDBAtlasEventTriggerDatabaseConfigDatabase(projectID, appID, `"INSERT", "UPDATE", "DELETE"`, &eventUpdated),
Config: testAccMongoDBAtlasEventTriggerDatabaseConfigDatabase(projectID, appID, `"INSERT", "UPDATE", "DELETE"`, &eventUpdated, true, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasEventTriggerExists(resourceName, &eventResp),
resource.TestCheckResourceAttr(resourceName, "project_id", projectID),
Expand Down Expand Up @@ -500,7 +499,7 @@ func testAccCheckMongoDBAtlasEventTriggerImportStateIDFunc(resourceName string)
}
}

func testAccMongoDBAtlasEventTriggerDatabaseConfigDatabase(projectID, appID, operationTypes string, eventTrigger *realm.EventTriggerRequest) string {
func testAccMongoDBAtlasEventTriggerDatabaseConfigDatabase(projectID, appID, operationTypes string, eventTrigger *realm.EventTriggerRequest, fullDoc, fullDocBefore bool) string {
return fmt.Sprintf(`
resource "mongodbatlas_event_trigger" "test" {
project_id = %[1]q
Expand All @@ -513,6 +512,8 @@ func testAccMongoDBAtlasEventTriggerDatabaseConfigDatabase(projectID, appID, ope
config_database = %[8]q
config_collection = %[9]q
config_service_id = %[10]q
config_full_document = %[11]t
config_full_document_before = %[12]t
config_match = <<-EOF
{
"updateDescription.updatedFields": {
Expand All @@ -523,7 +524,7 @@ func testAccMongoDBAtlasEventTriggerDatabaseConfigDatabase(projectID, appID, ope
}
`, projectID, appID, eventTrigger.Name, eventTrigger.Type, eventTrigger.FunctionID, *eventTrigger.Disabled, operationTypes,
eventTrigger.Config.Database, eventTrigger.Config.Collection,
eventTrigger.Config.ServiceID)
eventTrigger.Config.ServiceID, fullDoc, fullDocBefore)
}

func testAccMongoDBAtlasEventTriggerDatabaseConfigDatabaseEP(projectID, appID, operationTypes, awsAccID, awsRegion string, eventTrigger *realm.EventTriggerRequest) string {
Expand Down

0 comments on commit e7d51c4

Please sign in to comment.