Skip to content

feat(albwaf): onboard WAF - #1612

Open
SerseusWasTaken wants to merge 6 commits into
mainfrom
feat/onboard-waf-resource
Open

feat(albwaf): onboard WAF#1612
SerseusWasTaken wants to merge 6 commits into
mainfrom
feat/onboard-waf-resource

Conversation

@SerseusWasTaken

Copy link
Copy Markdown
Contributor

Relates to STACKITTPR-749

Description

Onboards WAF

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)

@SerseusWasTaken
SerseusWasTaken requested a review from a team as a code owner July 24, 2026 13:27
@SerseusWasTaken
SerseusWasTaken force-pushed the feat/onboard-waf-resource branch 3 times, most recently from 6cbea1f to 3a169c3 Compare July 27, 2026 08:22
mapvalidator.KeysAre(
stringvalidator.RegexMatches(
// Regex validates that no stackit- prefix is used
regexp.MustCompile(`^(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9_.-]{0,6}[a-zA-Z0-9]|(?:[a-rt-zA-Z0-9][a-zA-Z0-9_.-]{7}|s[a-su-zA-Z0-9_.-][a-zA-Z0-9_.-]{6}|st[b-zA-Z0-9_.-][a-zA-Z0-9_.-]{5}|sta[a-bd-zA-Z0-9_.-][a-zA-Z0-9_.-]{4}|stac[a-jl-zA-Z0-9_.-][a-zA-Z0-9_.-]{3}|stack[a-hj-zA-Z0-9_.-][a-zA-Z0-9_.-]{2}|stacki[a-su-zA-Z0-9_.-][a-zA-Z0-9_.-]|stackit[a-zA-Z0-9_.])[a-zA-Z0-9_.-]{0,54}[a-zA-Z0-9])$`),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This regex is ridiculously complex, but only because negative lookaheads not possible are using regexp.MustCompile.

@SerseusWasTaken
SerseusWasTaken force-pushed the feat/onboard-waf-resource branch 3 times, most recently from d9fa9f6 to 5b601ad Compare July 28, 2026 05:52
Comment thread docs/data-sources/alb_waf_configuration.md Outdated
Comment thread docs/resources/alb_waf_configuration.md Outdated
Comment thread docs/resources/alb_waf_configuration.md Outdated
Comment thread stackit/internal/services/albwaf/waf_configuration/datasource.go Outdated
Comment thread stackit/internal/services/albwaf/waf_configuration/datasource.go Outdated
Comment thread stackit/internal/services/albwaf/waf_configuration/resource.go Outdated
Comment thread stackit/internal/services/albwaf/waf_configuration/resource.go Outdated
Comment thread stackit/internal/services/albwaf/waf_configuration/resource.go Outdated
Comment thread stackit/internal/services/albwaf/waf_configuration/resource.go
}
}
return &waf.UpdateWAFPayload{
Name: 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.

Is the name in the update required? Based on the API docs, the update payload doesn't support a name attribute

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean. Name is part of the path parameters and thus required

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.

Yes, but the path parameters are usually not set in the payload itself. For example, projectId and region are also part of the path parameters, but they aren't set here, what is also correct.

Looks like the payload is wrong generated. Here in the spec, you can see that name, region and projectId are actually readOnly attributes:
https://github.com/stackitcloud/stackit-api-specifications/blob/166aed4c740698347e3e1c71e69341f77ebd7abb/services/alb-waf/v1beta/alb-waf.json#L898-L920

This should be reported to the service team, so that they update their API spec accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, i see now that the name is already declared in the first UpdateWAF call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Im simply gonna remove that argument, as it works without it anyway.

@SerseusWasTaken
SerseusWasTaken force-pushed the feat/onboard-waf-resource branch from 5b601ad to ff1b28b Compare July 31, 2026 06:50
Comment on lines -25 to +26
//go:embed testdata/managed-rule-set.tf
managedRuleSetConfig string
//go:embed testdata/resource-max.tf
wafConfig string

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.

In the acc tests the resources should be in independent tests. So for the managed rule set, it should remain like before and for the new waf_configuration, there should be a new test terraform config added with a separate test function.
Otherwise it will be difficult in the future to maintain it, when the test config grows with each new resource. In the new test config for waf_config, you can also add a waf_managed_rule_set. But there you don't need to add checks for the waf_managed_ruleset.
See for example the test configs of kms: https://github.com/stackitcloud/terraform-provider-stackit/tree/770998656083e829003cc3ed1c067739cc3033d3/stackit/internal/services/kms/testdata

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see. I re-added the deleted test and minimized the checks for waf managed rule set from the max test

@SerseusWasTaken
SerseusWasTaken force-pushed the feat/onboard-waf-resource branch from aefc49a to a4e8a7d Compare July 31, 2026 13:28
@SerseusWasTaken
SerseusWasTaken force-pushed the feat/onboard-waf-resource branch from a4e8a7d to 577c44b Compare July 31, 2026 13:33
@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/managed_rule_set 8.13% (-0.83%) 👎
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/waf_configuration 12.70% (+12.70%) 🎉

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
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.43% (-1.02%) 163 (-3) 17 (-2) 146 (-1) 👎
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/waf_configuration/datasource.go 0.00% (ø) 45 (+45) 0 45 (+45)
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/waf_configuration/resource.go 15.58% (+15.58%) 199 (+199) 31 (+31) 168 (+168) 🎉
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/managed_rule_set/resource_test.go
  • github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/albwaf/waf_configuration/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