Skip to content

azurerm_cdn_frontdoor_firewall_policy - add support for log_scrubbing block#28834

Merged
WodansSon merged 23 commits intomainfrom
e_frontdoor_log_scrubbing
Mar 6, 2025
Merged

azurerm_cdn_frontdoor_firewall_policy - add support for log_scrubbing block#28834
WodansSon merged 23 commits intomainfrom
e_frontdoor_log_scrubbing

Conversation

@WodansSon
Copy link
Collaborator

@WodansSon WodansSon commented Feb 21, 2025

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

  • Adding support for the newly exposed log scrubbing feature exposed in the new Frontdoor WAF policies API.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevant documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

image

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

  • azurerm_cdn_frontdoor_firewall_policy - add support for the log_scrubbing code block [GH-00000]

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #28236

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

@WodansSon WodansSon requested a review from a team as a code owner February 21, 2025 06:41
@WodansSon WodansSon marked this pull request as draft February 21, 2025 06:42
@WodansSon WodansSon added this to the v4.21.0 milestone Feb 24, 2025
Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Thanks @WodansSon - Just a few things to take a look at below if you could? Should be good to go when those are addressed (assuming tests pass, ofc!)

Comment on lines +459 to +469
"enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},

"rule": {
Type: pluginsdk.TypeList,
MaxItems: 100,
Optional: true,
Elem: &pluginsdk.Resource{
Copy link
Member

Choose a reason for hiding this comment

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

Is there a default rule / behaviour here if log_scrubbing is enabled, but no rules are defined? Just wondering, if there's no default behaviour, if these should be Required / MinItems instead to ensure the block does something?

(The test cases suggest that your design is fine, but I wanted to be sure since it's a little confusing to have this without rules?)

Suggested change
"enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},
"rule": {
Type: pluginsdk.TypeList,
MaxItems: 100,
Optional: true,
Elem: &pluginsdk.Resource{
"enabled": {
Type: pluginsdk.TypeBool,
Required: true,
},
"rule": {
Type: pluginsdk.TypeList,
MaxItems: 100,
Minitems: 1,
Elem: &pluginsdk.Resource{

Copy link
Collaborator Author

@WodansSon WodansSon Feb 27, 2025

Choose a reason for hiding this comment

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

No, there isn't a default behavior, per the service team:

Correction on the behavior of the LogScrubbing state.

  • If LogScrubbing State is set to Enabled but no scrubbing rules are configured, it will result in a no op (no operation).
  • For log scrubbing to take effect, both the LogScrubbing State (Enabled) and at least one Scrubbing Rule with State Enabled must be configured.

Comment on lines +1187 to +1188
// NOTE: If the 'operator' is set to 'Equals' the 'selector' cannot be 'nil'...
if *item.Selector == "" {
Copy link
Member

Choose a reason for hiding this comment

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

This looks a little off? We're checking for empty, not nil here? To avoid a panic, should this be:

Suggested change
// NOTE: If the 'operator' is set to 'Equals' the 'selector' cannot be 'nil'...
if *item.Selector == "" {
// NOTE: If the 'operator' is set to 'Equals' the 'selector' cannot be 'nil'...
if pointer.From(item.Selector) == "" {

since we're only setting item.Selector if there's a v["selector"] value present?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines +1193 to +1194
// NOTE: If the 'operator' is set to 'EqualsAny' the 'selector' must be 'nil'...
if *item.Selector != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Again here, should this be?

Suggested change
// NOTE: If the 'operator' is set to 'EqualsAny' the 'selector' must be 'nil'...
if *item.Selector != "" {
// NOTE: If the 'operator' is set to 'EqualsAny' the 'selector' must be 'nil'...
if item.Selector == nil {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

}

func TestAccCdnFrontDoorFirewallPolicy_logScrubbingComplete(t *testing.T) {
// NOTE: Regression test case for issue #19088
Copy link
Member

Choose a reason for hiding this comment

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

copy paste error?

Suggested change
// NOTE: Regression test case for issue #19088

Copy link
Collaborator Author

@WodansSon WodansSon Feb 27, 2025

Choose a reason for hiding this comment

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

Yes sir... DOH! 🤣 Fixed.

Comment on lines +848 to +862
tmp := r.template(data)
return fmt.Sprintf(`
%s

resource "azurerm_cdn_frontdoor_firewall_policy" "test" {
name = "accTestWAF%d"
resource_group_name = azurerm_resource_group.test.name
sku_name = azurerm_cdn_frontdoor_profile.test.sku_name
mode = "Prevention"

log_scrubbing {
enabled = true
}
}
`, tmp, data.RandomInteger)
Copy link
Member

Choose a reason for hiding this comment

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

We're pushing away from this pattern as it's unnecessary to assign the template to a var when it can be passed into the test directly. Would you mind updating these? (Just the new tests, don't worry about the others in the file, we'll be sorting this out more broadly in the future, just want to avoid more instances of it where possible. 🙈 )

Suggested change
tmp := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_cdn_frontdoor_firewall_policy" "test" {
name = "accTestWAF%d"
resource_group_name = azurerm_resource_group.test.name
sku_name = azurerm_cdn_frontdoor_profile.test.sku_name
mode = "Prevention"
log_scrubbing {
enabled = true
}
}
`, tmp, data.RandomInteger)
return fmt.Sprintf(`
%s
resource "azurerm_cdn_frontdoor_firewall_policy" "test" {
name = "accTestWAF%d"
resource_group_name = azurerm_resource_group.test.name
sku_name = azurerm_cdn_frontdoor_profile.test.sku_name
mode = "Prevention"
log_scrubbing {
enabled = true
}
}
`, r.template(data), data.RandomInteger)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since I will already be in the code I might as well just update all of them. Fixed.


* `enabled` - (Optional) Is log scrubbing enabled? Possible values are `true` or `false`. Defaults to `true`.

* `rule` - (Optional) One or more `scrubbing_rule` blocks as defined below.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `rule` - (Optional) One or more `scrubbing_rule` blocks as defined below.
* `rule` - (Optional) One or more `rule` blocks as defined below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above, the managed_rule also uses rule so I gave it a different name in the documentation trying to not confuse the end user when they are looking up what the scrubbing_rule block contains.

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Thanks @WodansSon - Just a few things to take a look at below if you could? Should be good to go when those are addressed (assuming tests pass, ofc!)

@WodansSon
Copy link
Collaborator Author

image

@WodansSon WodansSon modified the milestones: v4.21.0, v4.22.0 Mar 4, 2025
@WodansSon WodansSon dismissed jackofallops’s stale review March 4, 2025 11:04

Comments have been addressed...

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Thanks for the changes/responses @WodansSon - Given the external limitation, I don't think we will have to suck up a deviation from naming convention for now. I think once that's done, this should be good to go. Sorry for the back-and-forth.

Default: true,
},

"rule": {
Copy link
Member

Choose a reason for hiding this comment

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

As noted in the docs, if this doesn't match it will be difficult/frustrating for users to work out the correct block name. Since this is a limitation of the Registry docs, I don't think we have a choice here but to deviate from the convention due to the duplication of the block name in this resource.

Suggested change
"rule": {
"scrubbing_rule": {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@WodansSon
Copy link
Collaborator Author

image

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Thanks @WodansSon for the changes, this LGTM now 👍

@WodansSon WodansSon merged commit e66c290 into main Mar 6, 2025
35 checks passed
@WodansSon WodansSon deleted the e_frontdoor_log_scrubbing branch March 6, 2025 23:32
WodansSon added a commit that referenced this pull request Mar 6, 2025
jackofallops added a commit that referenced this pull request Mar 7, 2025
* Update CHANGELOG.md #28843

* Update CHANGELOG.md for #28748

* Update CHANGELOG.md for #28881

* Update CHANGELOG.md for #28909

* Update CHANGELOG.md fold in patch release and expand starred entry correctly

* Update CHANGELOG.md remove duplicate entry for 28843

* Update CHANGELOG.md #28066

* Update CHANGELOG.md for #28902 and fix ordering

* Update CHANGELOG.md for #28848

* Update CHANGELOG.md #27622

* Update CHANGELOG.md for #28271

* Update CHANGELOG.md update format

* Update CHANGELOG.md #28934

* Update for #28619 #28598

* Update CHANGELOG.md #28940

* Update CHANGELOG.md for #28880

* Update CHANGELOG.md for #28617

* Update CHANGELOG.md #28721

* Update CHANGELOG.md #28949

* Update previous entry for 4.16.0

* Update CHANGELOG.md for #28834

* prep for release

---------

Co-authored-by: Matthew Frahry <mbfrahry@gmail.com>
Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com>
Co-authored-by: catriona-m <86247157+catriona-m@users.noreply.github.com>
Co-authored-by: stephybun <steph@hashicorp.com>
Co-authored-by: Wodans Son <20408400+WodansSon@users.noreply.github.com>
Co-authored-by: jackofallops <ste@hashicorp.com>
@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2025

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azurerm_cdn_frontdoor_firewall_policy missing log scrubbing options

3 participants