Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTMDB-319: Add support for parameter unordered in resource_mongodbatlas_event_trigger #739

Merged
merged 8 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ require (
github.com/mwielbut/pointy v1.1.0
github.com/spf13/cast v1.5.0
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
go.mongodb.org/atlas v0.16.1-0.20220518082525-1080bb496bd4
go.mongodb.org/atlas v0.16.1-0.20220527133640-ba676d378a30
go.mongodb.org/realm v0.1.0
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,12 @@ go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsX
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
go.mongodb.org/atlas v0.15.1-0.20220215171307-4b760c3c624f h1:IvKkFdSSBLC5kqB1X87vn8CRAI7eXoMSK7u2lG+WUg8=
go.mongodb.org/atlas v0.15.1-0.20220215171307-4b760c3c624f/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
go.mongodb.org/atlas v0.16.0 h1:IqnDuK3XAZUgJ5lPHc4v4z4B8F6mvsS37O4ck7tOYVc=
go.mongodb.org/atlas v0.16.0/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
go.mongodb.org/atlas v0.16.1-0.20220518082525-1080bb496bd4 h1:l2rsLubhVznOdSspZcAUy8KjZAvqw9uichFO087edEI=
go.mongodb.org/atlas v0.16.1-0.20220518082525-1080bb496bd4/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
go.mongodb.org/atlas v0.16.1-0.20220527133640-ba676d378a30 h1:UVbPMJSXVDyvIA/JEHI2HAwc+B4R6xpnmSya/pbANpY=
go.mongodb.org/atlas v0.16.1-0.20220527133640-ba676d378a30/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=
Expand Down
7 changes: 7 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_event_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func dataSourceMongoDBAtlasEventTrigger() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"unordered": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -191,6 +195,9 @@ func dataSourceMongoDBAtlasEventTriggerRead(ctx context.Context, d *schema.Resou
if err = d.Set("config_schedule_type", eventResp.Config.ScheduleType); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "config_schedule_type", projectID, appID, err))
}
if err = d.Set("unordered", eventResp.Config.Unordered); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "unordered", projectID, appID, err))
}
if err = d.Set("event_processors", flattenTriggerEventProcessorAWSEventBridge(eventResp.EventProcessors)); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "event_processors", projectID, appID, err))
}
Expand Down
4 changes: 3 additions & 1 deletion mongodbatlas/data_source_mongodbatlas_event_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccDataSourceMongoDBAtlasEventTrigger_basic(t *testing.T) {
Collection: "listingsAndReviews",
ServiceID: os.Getenv("MONGODB_REALM_SERVICE_ID"),
FullDocument: pointy.Bool(false),
Unordered: pointy.Bool(true),
},
}

Expand Down Expand Up @@ -58,6 +59,7 @@ func testAccMongoDBAtlasDataSourceEventTriggerConfig(projectID, appID, operation
type = %[4]q
function_id = %[5]q
disabled = %[6]t
unordered = %[7]t
config_operation_types = [%s]
config_database = %[8]q
config_collection = %[9]q
Expand All @@ -70,7 +72,7 @@ func testAccMongoDBAtlasDataSourceEventTriggerConfig(projectID, appID, operation
app_id = mongodbatlas_event_trigger.test.app_id
trigger_id = mongodbatlas_event_trigger.test.id
}
`, projectID, appID, eventTrigger.Name, eventTrigger.Type, eventTrigger.FunctionID, *eventTrigger.Disabled, operationTypes,
`, projectID, appID, eventTrigger.Name, eventTrigger.Type, eventTrigger.FunctionID, *eventTrigger.Disabled, *eventTrigger.Config.Unordered, operationTypes,
eventTrigger.Config.Database, eventTrigger.Config.Collection,
eventTrigger.Config.ServiceID)
}
5 changes: 5 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_event_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func dataSourceMongoDBAtlasEventTriggers() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"unordered": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -190,6 +194,7 @@ func flattenEventTriggers(eventTriggers []realm.EventTrigger) []map[string]inter
"config_schedule": eventTriggers[i].Config.Schedule,
"config_schedule_type": eventTriggers[i].Config.ScheduleType,
"event_processors": flattenTriggerEventProcessorAWSEventBridge(eventTriggers[i].EventProcessors),
"unordered": eventTriggers[i].Config.Unordered,
andreaangiolillo marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion mongodbatlas/data_source_mongodbatlas_event_triggers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestAccDataSourceMongoDBAtlasEventTriggers_basic(t *testing.T) {
ServiceID: os.Getenv("MONGODB_REALM_SERVICE_ID"),
FullDocument: pointy.Bool(false),
Schedule: "*",
Unordered: pointy.Bool(true),
},
}

Expand All @@ -59,6 +60,7 @@ func testAccMongoDBAtlasEventTriggersDataSourceConfig(projectID, appID, operatio
type = %[4]q
function_id = %[5]q
disabled = %[6]t
unordered = %[7]t
config_operation_types = [%s]
config_database = %[8]q
config_collection = %[9]q
Expand All @@ -70,7 +72,7 @@ func testAccMongoDBAtlasEventTriggersDataSourceConfig(projectID, appID, operatio
project_id = mongodbatlas_event_trigger.test.project_id
app_id = mongodbatlas_event_trigger.test.app_id
}
`, projectID, appID, eventTrigger.Name, eventTrigger.Type, eventTrigger.FunctionID, *eventTrigger.Disabled, operationTypes,
`, projectID, appID, eventTrigger.Name, eventTrigger.Type, eventTrigger.FunctionID, *eventTrigger.Disabled, *eventTrigger.Config.Unordered, operationTypes,
eventTrigger.Config.Database, eventTrigger.Config.Collection,
eventTrigger.Config.ServiceID)
}
13 changes: 13 additions & 0 deletions mongodbatlas/resource_mongodbatlas_event_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func resourceMongoDBAtlasEventTriggers() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"unordered": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -282,6 +287,10 @@ func resourceMongoDBAtlasEventTriggersCreate(ctx context.Context, d *schema.Reso
eventTriggerReq.EventProcessors = expandTriggerEventProcessorAWSEventBridge(v.([]interface{}))
}

if v, ok := d.GetOk("unordered"); ok {
eventTriggerConfig.Unordered = pointy.Bool(v.(bool))
}

eventTriggerReq.Config = eventTriggerConfig

eventResp, _, err := conn.EventTriggers.Create(context.Background(), projectID, appID, eventTriggerReq)
Expand Down Expand Up @@ -378,6 +387,9 @@ func resourceMongoDBAtlasEventTriggersRead(ctx context.Context, d *schema.Resour
if err = d.Set("config_schedule_type", resp.Config.ScheduleType); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "config_schedule_type", projectID, appID, err))
}
if err = d.Set("unordered", resp.Config.Unordered); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "unordered", projectID, appID, err))
}
if err = d.Set("event_processors", flattenTriggerEventProcessorAWSEventBridge(resp.EventProcessors)); err != nil {
return diag.FromErr(fmt.Errorf(errorEventTriggersSetting, "event_processors", projectID, appID, err))
}
Expand Down Expand Up @@ -417,6 +429,7 @@ func resourceMongoDBAtlasEventTriggersUpdate(ctx context.Context, d *schema.Reso
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))
eventTriggerConfig.Unordered = pointy.Bool(d.Get("unordered").(bool))
}
if typeTrigger == "AUTHENTICATION" {
eventTriggerConfig.OperationType = d.Get("config_operation_type").(string)
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/event_trigger.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ In addition to all arguments above, the following attributes are exported:
* `config_match` - A [$match](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) expression document that MongoDB Realm includes in the underlying change stream pipeline for the trigger.
* `config_project` - A [$project](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) expression document that Realm uses to filter the fields that appear in change event objects.
* `config_full_document` - If true, indicates that `UPDATE` change events should include the most current [majority-committed](https://docs.mongodb.com/manual/reference/read-concern-majority/) version of the modified document in the fullDocument field.
* `unordered` - Only Available for Database Triggers. If true, event ordering is disabled and this trigger can process events in parallel. If false, event ordering is enabled and the trigger executes serially.
* `config_schedule` - A [cron expression](https://docs.mongodb.com/realm/triggers/cron-expressions/) that defines the trigger schedule.
* `event_processors` - An object where each field name is an event processor ID and each value is an object that configures its corresponding event processor.
* `event_processors.0.aws_eventbridge.config_account_id` - AWS Account ID.
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/event_triggers.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ In addition to all arguments above, the following attributes are exported:
* `config_match` - A [$match](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) expression document that MongoDB Realm includes in the underlying change stream pipeline for the trigger.
* `config_project` - A [$project](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) expression document that Realm uses to filter the fields that appear in change event objects.
* `config_full_document` - If true, indicates that `UPDATE` change events should include the most current [majority-committed](https://docs.mongodb.com/manual/reference/read-concern-majority/) version of the modified document in the fullDocument field.
* `unordered` - Sort order for `DATABASE` type.
martinstibbe marked this conversation as resolved.
Show resolved Hide resolved
* `config_schedule` - A [cron expression](https://docs.mongodb.com/realm/triggers/cron-expressions/) that defines the trigger schedule.
* `event_processors` - An object where each field name is an event processor ID and each value is an object that configures its corresponding event processor.
* `event_processors.0.aws_eventbridge.config_account_id` - AWS Account ID.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/event_trigger.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resource "mongodbatlas_event_trigger" "test" {
name = "NAME OF THE TRIGGER"
type = "DATABASE"
disabled = false
unordered = false
config_operation_types = ["INSERT", "UPDATE"]
config_operation_type = "LOGIN"
config_providers = ["anon-user"]
Expand Down Expand Up @@ -116,6 +117,7 @@ resource "mongodbatlas_event_trigger" "test" {
* `config_match` - (Optional) Optional for `DATABASE` type. A [$match](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) expression document that MongoDB Realm includes in the underlying change stream pipeline for the trigger. This is useful when you want to filter change events beyond their operation type. The trigger will only fire if the expression evaluates to true for a given change event.
* `config_project` - (Optional) Optional for `DATABASE` type. A [$project](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) expression document that Realm uses to filter the fields that appear in change event objects.
* `config_full_document` - (Optional) Optional for `DATABASE` type. If true, indicates that `UPDATE` change events should include the most current [majority-committed](https://docs.mongodb.com/manual/reference/read-concern-majority/) version of the modified document in the fullDocument field.
* `unordered` - Only Available for Database Triggers. If true, event ordering is disabled and this trigger can process events in parallel. If false, event ordering is enabled and the trigger executes serially.
* `config_schedule` - (Optional) Required for `SCHEDULED` type. A [cron expression](https://docs.mongodb.com/realm/triggers/cron-expressions/) that defines the trigger schedule.
* `event_processors` - (Optional) An object where each field name is an event processor ID and each value is an object that configures its corresponding event processor. The following event processors are supported: `AWS_EVENTBRIDGE` For an example configuration object, see [Send Trigger Events to AWS EventBridge](https://docs.mongodb.com/realm/triggers/eventbridge/#std-label-event_processor_example).
* `event_processors.0.aws_eventbridge.config_account_id` - (Optional) AWS Account ID.
Expand Down