Skip to content

Feature/waf onboard custom rule group - #1620

Open
Manuelvaas wants to merge 8 commits into
mainfrom
feature/waf-onboard-custom-rule-group
Open

Feature/waf onboard custom rule group#1620
Manuelvaas wants to merge 8 commits into
mainfrom
feature/waf-onboard-custom-rule-group

Conversation

@Manuelvaas

Copy link
Copy Markdown
Contributor

Description

relates to STACKITTPR-748

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@Manuelvaas
Manuelvaas requested a review from a team as a code owner July 28, 2026 14:51

@SerseusWasTaken SerseusWasTaken left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

look pretty clean, but found an issue during testing:
Using this config:

resource "stackit_alb_waf_custom_rule_group" "custom_rule_group" {
  project_id = local.project_id
  name       = "some-name"
  rules = [
    {
      behavior = {
        action = "ACTION_DENY"
        log    = true
      }
      conditions = [
        {
          operator = {
            type  = "OPERATOR_VALIDATE_UTF8_ENCODING"
            value = "dummy"
          }
          variable = {
            type = "VARIABLE_RESPONSE_STATUS"
          }
        }
      ]
    }
  ]
}

terraform apply runs successfully, but after changing rules[0].behavior.log to false, i got this error:

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to stackit_alb_waf_custom_rule_group.custom_rule_group, provider "provider[\"registry.terraform.io/stackitcloud/stackit\"]" produced an unexpected new value: .rules[0].behavior.log: was cty.False, but now null.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

"rule_id": "Backend auto-allocated unique rule ID within the valid 1-99999 threshold.",
"behavior_action": "The protective stance action. ACTION_DENY forces a 403 status response code.",
"behavior_log": "Determines whether an entry should be generated in the security ledger upon a rule hit.",
"behavior_log_msg": "Custom notification message string mapped to underlying logdata contexts. Required if log is true.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"behavior_log_msg": "Custom notification message string mapped to underlying logdata contexts. Required if log is true.",
"behavior_log_msg": "Custom notification message string mapped to underlying logdata contexts. Required if behavior_log is true.",

rules := []RuleModel{}
diags := model.Rules.ElementsAs(ctx, &rules, true)
if diags.HasError() {
return nil, fmt.Errorf("converting to rule map: %v", diags.Errors())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe use `core.DiagsToError(diags) here (and at the other instances) instead?

Suggested change
return nil, fmt.Errorf("converting to rule map: %v", diags.Errors())
return nil, fmt.Errorf("converting to rule map: %w", core.DiagsToError(diags))

Comment on lines +567 to +569
if err != nil || conditions == nil {
return nil, fmt.Errorf("converting conditions: %w", err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick: given err == nil but conditions != nil this would result in a unhelpful error message. This is highly unlikely to happen though, so feel free to ignore it

}

model.Id = tfutils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, model.Name.ValueString())
model.Name = types.StringValue(model.Name.ValueString())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this rather be something like this?

Suggested change
model.Name = types.StringValue(model.Name.ValueString())
model.Name = types.StringValue(*customRuleGroup.Name)

@github-actions

Copy link
Copy Markdown

Merging this branch changes the coverage (1 decrease, 1 increase)

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/terraform-provider-stackit/stackit 1.17% (ø)
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf 0.00% (ø)
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/custom_rule_group 31.94% (+31.94%) 🌟
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/managed_rule_set 8.37% (-0.59%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/custom_rule_group/datasource.go 0.00% (ø) 46 (+46) 0 46 (+46)
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/custom_rule_group/resource.go 38.02% (+38.02%) 242 (+242) 92 (+92) 150 (+150) 🌟
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/managed_rule_set/datasource.go 0.00% (ø) 46 0 46
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/managed_rule_set/resource.go 10.83% (-0.62%) 157 (-9) 17 (-2) 140 (-7) 👎
github.com/stackitcloud/terraform-provider-stackit/stackit/provider.go 1.17% (ø) 171 2 169

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/albwaf_acc_test.go
  • github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/custom_rule_group/resource_test.go
  • github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/managed_rule_set/resource_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants