From 20b22e3b07923680a803ff9480413ea885b17b85 Mon Sep 17 00:00:00 2001
From: Patrick Cowland <44225864+patrickcping@users.noreply.github.com>
Date: Mon, 18 Nov 2024 11:28:41 +0000
Subject: [PATCH] `pingone_risk_predictor`: Add the
`predictor_bot_detection.include_repeated_events_without_sdk` field (#939)
* `pingone_risk_predictor`: Add the `predictor_bot_detection.include_repeated_events_without_sdk` field
* changelog
---
.changelog/939.txt | 3 ++
docs/resources/risk_predictor.md | 4 ++
.../service/risk/resource_risk_predictor.go | 45 ++++++++++++++++---
.../risk/resource_risk_predictor_test.go | 14 +++---
4 files changed, 55 insertions(+), 11 deletions(-)
create mode 100644 .changelog/939.txt
diff --git a/.changelog/939.txt b/.changelog/939.txt
new file mode 100644
index 00000000..92ab1635
--- /dev/null
+++ b/.changelog/939.txt
@@ -0,0 +1,3 @@
+```release-note:enhancement
+`resource/pingone_risk_predictor`: Added the `predictor_bot_detection.include_repeated_events_without_sdk` field to choose whether to expand the range of bot activity that PingOne Protect can detect.
+```
diff --git a/docs/resources/risk_predictor.md b/docs/resources/risk_predictor.md
index eac9eaed..febbf93f 100644
--- a/docs/resources/risk_predictor.md
+++ b/docs/resources/risk_predictor.md
@@ -495,6 +495,10 @@ Optional:
### Nested Schema for `predictor_bot_detection`
+Optional:
+
+- `include_repeated_events_without_sdk` (Boolean) A boolean that specifies whether to expand the range of bot activity that PingOne Protect can detect.
+
### Nested Schema for `predictor_composite`
diff --git a/internal/service/risk/resource_risk_predictor.go b/internal/service/risk/resource_risk_predictor.go
index 97d87ad7..74bbaa41 100644
--- a/internal/service/risk/resource_risk_predictor.go
+++ b/internal/service/risk/resource_risk_predictor.go
@@ -83,6 +83,11 @@ type predictorGenericAllowedDomain struct {
AllowedDomainList types.Set `tfsdk:"allowed_domain_list"`
}
+// Bot Detection
+type predictorBotDetection struct {
+ IncludeRepeatedEventsWithoutSDK types.Bool `tfsdk:"include_repeated_events_without_sdk"`
+}
+
// Composite
type predictorComposite struct {
Composition types.Object `tfsdk:"composition"`
@@ -215,6 +220,11 @@ var (
"allowed_domain_list": types.SetType{ElemType: types.StringType},
}
+ // Bot Detection
+ predictorBotDetectionTFObjectTypes = map[string]attr.Type{
+ "include_repeated_events_without_sdk": types.BoolType,
+ }
+
// Composite
predictorCompositeTFObjectTypes = map[string]attr.Type{
"composition": types.ObjectType{
@@ -701,7 +711,12 @@ func (r *RiskPredictorResource) Schema(ctx context.Context, req resource.SchemaR
MarkdownDescription: predictorBotDetectionDescription.MarkdownDescription,
Optional: true,
- Attributes: map[string]schema.Attribute{},
+ Attributes: map[string]schema.Attribute{
+ "include_repeated_events_without_sdk": schema.BoolAttribute{
+ Description: framework.SchemaAttributeDescriptionFromMarkdown("A boolean that specifies whether to expand the range of bot activity that PingOne Protect can detect.").Description,
+ Optional: true,
+ },
+ },
Validators: predictorObjectValidators,
@@ -1876,7 +1891,7 @@ func (p *riskPredictorResourceModel) expand(ctx context.Context, apiClient *risk
}
if !p.PredictorBotDetection.IsNull() && !p.PredictorBotDetection.IsUnknown() {
- riskPredictor.RiskPredictorBotDetection = p.expandPredictorBotDetection(riskPredictorCommonData)
+ riskPredictor.RiskPredictorBotDetection, d = p.expandPredictorBotDetection(ctx, riskPredictorCommonData)
}
if !p.PredictorComposite.IsNull() && !p.PredictorComposite.IsUnknown() {
@@ -2005,7 +2020,9 @@ func (p *riskPredictorResourceModel) expandPredictorAnonymousNetwork(ctx context
return &data, diags
}
-func (p *riskPredictorResourceModel) expandPredictorBotDetection(riskPredictorCommon *risk.RiskPredictorCommon) *risk.RiskPredictorBotDetection {
+func (p *riskPredictorResourceModel) expandPredictorBotDetection(ctx context.Context, riskPredictorCommon *risk.RiskPredictorCommon) (*risk.RiskPredictorBotDetection, diag.Diagnostics) {
+ var diags diag.Diagnostics
+
data := risk.RiskPredictorBotDetection{
Name: riskPredictorCommon.Name,
CompactName: riskPredictorCommon.CompactName,
@@ -2014,7 +2031,21 @@ func (p *riskPredictorResourceModel) expandPredictorBotDetection(riskPredictorCo
Default: riskPredictorCommon.Default,
}
- return &data
+ var predictorPlan predictorBotDetection
+ d := p.PredictorBotDetection.As(ctx, &predictorPlan, basetypes.ObjectAsOptions{
+ UnhandledNullAsEmpty: false,
+ UnhandledUnknownAsEmpty: false,
+ })
+ diags.Append(d...)
+ if diags.HasError() {
+ return nil, diags
+ }
+
+ if !predictorPlan.IncludeRepeatedEventsWithoutSDK.IsNull() && !predictorPlan.IncludeRepeatedEventsWithoutSDK.IsUnknown() {
+ data.SetIncludeRepeatedEventsWithoutSdk(predictorPlan.IncludeRepeatedEventsWithoutSDK.ValueBool())
+ }
+
+ return &data, diags
}
func (p *riskPredictorResourceModel) expandPredictorComposite(ctx context.Context, riskPredictorCommon *risk.RiskPredictorCommon) (*risk.RiskPredictorComposite, diag.Diagnostics) {
@@ -3213,10 +3244,12 @@ func (p *riskPredictorResourceModel) toStateRiskPredictorBotDetection(apiObject
var diags diag.Diagnostics
if apiObject == nil || apiObject.GetId() == "" {
- return types.ObjectNull(map[string]attr.Type{}), diags
+ return types.ObjectNull(predictorBotDetectionTFObjectTypes), diags
}
- objValue, d := types.ObjectValue(map[string]attr.Type{}, map[string]attr.Value{})
+ objValue, d := types.ObjectValue(predictorBotDetectionTFObjectTypes, map[string]attr.Value{
+ "include_repeated_events_without_sdk": framework.BoolOkToTF(apiObject.GetIncludeRepeatedEventsWithoutSdkOk()),
+ })
diags.Append(d...)
return objValue, diags
diff --git a/internal/service/risk/resource_risk_predictor_test.go b/internal/service/risk/resource_risk_predictor_test.go
index d2d04fd4..75b8cb88 100644
--- a/internal/service/risk/resource_risk_predictor_test.go
+++ b/internal/service/risk/resource_risk_predictor_test.go
@@ -567,14 +567,14 @@ func TestAccRiskPredictor_Bot_Detection(t *testing.T) {
resource.TestCheckResourceAttr(resourceFullName, "type", "BOT"),
resource.TestCheckResourceAttr(resourceFullName, "deletable", "true"),
resource.TestCheckResourceAttr(resourceFullName, "default.result.level", "MEDIUM"),
- resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.#", "0"),
+ resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.include_repeated_events_without_sdk", "true"),
)
minimalCheck := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceFullName, "type", "BOT"),
resource.TestCheckResourceAttr(resourceFullName, "deletable", "true"),
resource.TestCheckNoResourceAttr(resourceFullName, "default.result.level"),
- resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.#", "0"),
+ resource.TestCheckNoResourceAttr(resourceFullName, "predictor_bot_detection.include_repeated_events_without_sdk"),
)
resource.Test(t, resource.TestCase{
@@ -652,7 +652,7 @@ func TestAccRiskPredictor_Bot_Detection_OverwriteUndeletable(t *testing.T) {
resource.TestCheckResourceAttr(resourceFullName, "type", "BOT"),
resource.TestCheckResourceAttr(resourceFullName, "deletable", "false"),
resource.TestCheckResourceAttr(resourceFullName, "default.result.level", "MEDIUM"),
- resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.#", "0"),
+ resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.include_repeated_events_without_sdk", "true"),
)
resource.Test(t, resource.TestCase{
@@ -2494,7 +2494,9 @@ resource "pingone_risk_predictor" "%[2]s" {
}
}
- predictor_bot_detection = {}
+ predictor_bot_detection = {
+ include_repeated_events_without_sdk = true
+ }
}`, acctest.GenericSandboxEnvironment(), resourceName, name)
}
@@ -2529,7 +2531,9 @@ resource "pingone_risk_predictor" "%[2]s" {
}
}
- predictor_bot_detection = {}
+ predictor_bot_detection = {
+ include_repeated_events_without_sdk = true
+ }
}`, acctest.GenericSandboxEnvironment(), resourceName, name, compactName)
}