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

Add webhook event log retention policy configuration #289

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion docs/resources/system_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ resource "fusionauth_system_configuration" "example" {
* `ui_configuration` - (Optional)
- `header_color` - (Optional) A hexadecimal color to override the default menu color in the user interface.
- `logo_url` - (Optional) A URL of a logo to override the default FusionAuth logo in the user interface.
- `menu_font_color` - (Optional) A hexadecimal color to override the default menu font color in the user interface.
- `menu_font_color` - (Optional) A hexadecimal color to override the default menu font color in the user interface.
* `webhook_event_log_configuration` - (Optional)
- `delete` - (Optional)
* `enabled` - (Optional) Whether or not FusionAuth should delete the webhook event logs based upon this configuration. When true the webhookEventLogConfiguration.delete.numberOfDaysToRetain will be used to identify webhook event logs that are eligible for deletion. When this value is set to false webhook event logs will be preserved forever.
* `number_of_days_to_retain` - (Optional) The number of days to retain webhook event logs.
54 changes: 54 additions & 0 deletions fusionauth/resource_system_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,39 @@ func resourceSystemConfiguration() *schema.Resource {
},
},
},
"webhook_event_log_configuration": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"delete": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work, but there is also a fusionauth.Enableable struct that you may want to use to reduce boilerplate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was modeling this after the way that audit log configuration does it. None of the other Enableables use that struct in this resourceSystemConfiguration() function, but I did notice the new configuration was missing in getDefaultSystemConfigurationRequest() and added it there using fusionauth.Enableable.

Is fusionauth.Enableable usable in this function, and it's just not using that pattern? I admit I may need an example to reference for that update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to test this locally. I think that fusionauth.Enableable is from the go client, but this portion is describing what it looks like in TF. I don't think it's possible to use that type here, but I was able to apply changes using this new configuration.

Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether or not FusionAuth should delete the webhook event logs based upon this configuration. When true the webhookEventLogConfiguration.delete.numberOfDaysToRetain will be used to identify webhook event logs that are eligible for deletion. When this value is set to false webhook event logs will be preserved forever.",
},
"number_of_days_to_retain": {
Type: schema.TypeInt,
Optional: true,
Default: 365,
Description: "The number of days to retain webhook event logs.",
},
},
},
},
},
},
},
},
}
}
Expand Down Expand Up @@ -304,6 +337,13 @@ func buildSystemConfigurationRequest(data *schema.ResourceData) fusionauth.Syste
sc.SystemConfiguration.UiConfiguration.MenuFontColor = v.(string)
}

if v, ok := data.GetOk("webhook_event_log_configuration.0.delete.0.enabled"); ok {
sc.SystemConfiguration.WebhookEventLogConfiguration.Delete.Enabled = v.(bool)
}
if v, ok := data.GetOk("webhook_event_log_configuration.0.delete.0.number_of_days_to_retain"); ok {
sc.SystemConfiguration.WebhookEventLogConfiguration.Delete.NumberOfDaysToRetain = v.(int)
}

return sc
}

Expand Down Expand Up @@ -375,6 +415,20 @@ func buildResourceFromSystemConfiguration(sc fusionauth.SystemConfiguration, dat
return diag.Errorf("system_configuration.ui_configuration: %s", err.Error())
}

err = data.Set("webhook_event_log_configuration", []map[string]interface{}{
{
"delete": []map[string]interface{}{
{
"enabled": sc.WebhookEventLogConfiguration.Delete.Enabled,
"number_of_days_to_retain": sc.WebhookEventLogConfiguration.Delete.NumberOfDaysToRetain,
},
},
},
})
if err != nil {
return diag.Errorf("system_configuration.webhook_event_log_configuration: %s", err.Error())
}

return nil
}

Expand Down