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

azurerm_sentinel_alert_rule_fusion - remove existing check for built in rule #27653

Merged
merged 11 commits into from
Nov 7, 2024

Conversation

ziyeqf
Copy link
Contributor

@ziyeqf ziyeqf commented Oct 15, 2024

The only one fusion alert rule is enabled by default ( source ), so removing the existing check and update the document.

In my opinion we can deprecate the name and template_alert_rule_guid and remove them in v5.0, however this will be a breaking change, and the resource also needs to be refactored to typed sdk, to make the resource able to be used, I just removed the existing check in this PR.

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

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 relevent 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)
❯❯ tftest sentinel TestAccSentinelAlertRuleFusion_
=== RUN   TestAccSentinelAlertRuleFusion_basic
=== PAUSE TestAccSentinelAlertRuleFusion_basic
=== RUN   TestAccSentinelAlertRuleFusion_disable
=== PAUSE TestAccSentinelAlertRuleFusion_disable
=== RUN   TestAccSentinelAlertRuleFusion_sourceSetting
=== PAUSE TestAccSentinelAlertRuleFusion_sourceSetting
=== CONT  TestAccSentinelAlertRuleFusion_basic
=== CONT  TestAccSentinelAlertRuleFusion_sourceSetting
=== CONT  TestAccSentinelAlertRuleFusion_disable
--- PASS: TestAccSentinelAlertRuleFusion_basic (265.21s)
--- PASS: TestAccSentinelAlertRuleFusion_sourceSetting (310.56s)
--- PASS: TestAccSentinelAlertRuleFusion_disable (416.85s)
PASS
ok  	github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel	416.940s

Change Log

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

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)

Note

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

@@ -50,6 +41,7 @@ resource "azurerm_sentinel_alert_rule_fusion" "example" {
The following arguments are supported:

* `name` - (Required) The name which should be used for this Sentinel Fusion Alert Rule. Changing this forces a new Sentinel Fusion Alert Rule to be created.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can name ONLY be BuiltInFusion? if so could we please add that as a default, make the property optional, and deprecate it.

or can additional rules be added? or the existing ones name renamed?

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'm not sure about the already existing rules with different names, for new created ones, it can only be BuiltInFusion

@github-actions github-actions bot added size/XL and removed size/L labels Oct 30, 2024
@ziyeqf
Copy link
Contributor Author

ziyeqf commented Oct 30, 2024

just triggered another testing, maybe we can wait for it.

Comment on lines 46 to 47
* `name` - (Optional) The name which should be used for this Sentinel Fusion Alert Rule. Changing this forces a new Sentinel Fusion Alert Rule to be created.
**Note:** The `name` is deprecated and will be removed in v5.0 version of the provider. The Fusion Alert Rule is enabled by default with the name `BuiltInFusion`, more details could be found [here](https://learn.microsoft.com/en-us/azure/sentinel/configure-fusion-rules#configure-scheduled-analytics-rules-for-fusion-detections).
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't follow our guidelines for breaking changes.

Please also make sure the upgrade guide is updated with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, sorry for missed that part.

@ziyeqf
Copy link
Contributor Author

ziyeqf commented Oct 30, 2024

updated testing result

❯❯ tftest sentinel TestAccSentinelAlertRuleFusion_
=== RUN   TestAccSentinelAlertRuleFusion_basic
=== PAUSE TestAccSentinelAlertRuleFusion_basic
=== RUN   TestAccSentinelAlertRuleFusion_disable
=== PAUSE TestAccSentinelAlertRuleFusion_disable
=== RUN   TestAccSentinelAlertRuleFusion_sourceSetting
=== PAUSE TestAccSentinelAlertRuleFusion_sourceSetting
=== CONT  TestAccSentinelAlertRuleFusion_basic
=== CONT  TestAccSentinelAlertRuleFusion_sourceSetting
=== CONT  TestAccSentinelAlertRuleFusion_disable
--- PASS: TestAccSentinelAlertRuleFusion_basic (488.65s)
--- PASS: TestAccSentinelAlertRuleFusion_sourceSetting (553.41s)
--- PASS: TestAccSentinelAlertRuleFusion_disable (901.94s)
PASS
ok  	github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel	902.014s

Comment on lines 46 to 47
* `name` - (Optional) The name which should be used for this Sentinel Fusion Alert Rule. Changing this forces a new Sentinel Fusion Alert Rule to be created. Defaults to `BuiltInFusion`

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't advertise or encourage the use of deprecated properties which is why we remove them from the documentation entirely.

Suggested change
* `name` - (Optional) The name which should be used for this Sentinel Fusion Alert Rule. Changing this forces a new Sentinel Fusion Alert Rule to be created. Defaults to `BuiltInFusion`

@ziyeqf
Copy link
Contributor Author

ziyeqf commented Nov 6, 2024

kindly bubble this PR up

Comment on lines 165 to 167
if _, err := client.CreateOrUpdate(ctx, id, params); err != nil {
return fmt.Errorf("creating Sentinel Alert Rule Fusion %q: %+v", id, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

The string formatter for the IDs contain detailed information about the resource's name, we would be unnecessarily repeating ourselves by adding that in the error message.

Suggested change
if _, err := client.CreateOrUpdate(ctx, id, params); err != nil {
return fmt.Errorf("creating Sentinel Alert Rule Fusion %q: %+v", id, err)
}
if _, err := client.CreateOrUpdate(ctx, id, params); err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
}


resp, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("retrieving %q: %+v", id, err)
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
return fmt.Errorf("retrieving %q: %+v", id, err)
return fmt.Errorf("retrieving %s: %+v", id, err)

Copy link
Member

Choose a reason for hiding this comment

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

Hasn't been updated

ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
Schema: resourceSentinelAlertRuleFusionSchema(),
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the schema in-lined here

}

if err = assertAlertRuleKind(resp.Model, alertrules.AlertRuleKindFusion); err != nil {
return fmt.Errorf("asserting alert rule of %q: %+v", id, err)
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
return fmt.Errorf("asserting alert rule of %q: %+v", id, err)
return fmt.Errorf("asserting alert rule of %s: %+v", id, err)

Comment on lines 193 to 194
payload := resp.Model.(alertrules.FusionAlertRule)

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't follow the pattern that we expect for the update function which

  1. nil check Model
  2. nil check Properties
  3. Patch changes in to Properties/Model

This particular case will deviate slightly since this is a discriminated type and it's generally good practice to check that the type assertion we're doing is successful and throwing an error if it isnt. Can you please update this to

Suggested change
payload := resp.Model.(alertrules.FusionAlertRule)
if resp.Model == nil {
return fmt.Errorf("retrieving %s: `model` was nil", id)
}
payload, ok := resp.Model.(alertrules.FusionAlertRule)
if !ok {
return fmt.Errorf("retrieving %s: expected an alert rule of type `Fusion`, got %q", pointer.From(resp.Model.AlertRule().Type))
}
if payload.Properties == nil {
return fmt.Errorf("retrieving %s: `properties` was nil", id)
}

Comment on lines 203 to 205
if payload.Properties == nil {
payload.Properties = &alertrules.FusionAlertRuleProperties{}
}
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Suggested change
if payload.Properties == nil {
payload.Properties = &alertrules.FusionAlertRuleProperties{}
}

Comment on lines 210 to 212
if payload.Properties == nil {
payload.Properties = &alertrules.FusionAlertRuleProperties{}
}
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Suggested change
if payload.Properties == nil {
payload.Properties = &alertrules.FusionAlertRuleProperties{}
}

Comment on lines 217 to 223
if payload.Properties != nil {
payload.Properties.Description = nil
payload.Properties.DisplayName = nil
payload.Properties.LastModifiedUtc = nil
payload.Properties.Severity = nil
payload.Properties.Tactics = nil
}
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to nil check this anymore since we're doing it further up

Suggested change
if payload.Properties != nil {
payload.Properties.Description = nil
payload.Properties.DisplayName = nil
payload.Properties.LastModifiedUtc = nil
payload.Properties.Severity = nil
payload.Properties.Tactics = nil
}
payload.Properties.Description = nil
payload.Properties.DisplayName = nil
payload.Properties.LastModifiedUtc = nil
payload.Properties.Severity = nil
payload.Properties.Tactics = nil

}

d.SetId(id.ID())
if _, err := client.CreateOrUpdate(ctx, *id, payload); err != nil {
return fmt.Errorf("creating Sentinel Alert Rule Fusion %q: %+v", id, err)
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
return fmt.Errorf("creating Sentinel Alert Rule Fusion %q: %+v", id, err)
return fmt.Errorf("updating %s: %+v", id, err)

Comment on lines 58 to 61

### `azurerm_sentinel_alert_rule_fusion`

* The deprecated `name` property has been removed.
Copy link
Member

Choose a reason for hiding this comment

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

This has been put inside the ```markdown box where we've put examples of how the breaking changes should be documented, this should be moved down out of this block

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

@ziyeqf can you please provide testing evidence in 5.0 mode as well

@ziyeqf
Copy link
Contributor Author

ziyeqf commented Nov 7, 2024

4.0 test result

❯❯ tftest sentinel TestAccSentinelAlertRuleFusion_
=== RUN   TestAccSentinelAlertRuleFusion_basic
=== PAUSE TestAccSentinelAlertRuleFusion_basic
=== RUN   TestAccSentinelAlertRuleFusion_disable
=== PAUSE TestAccSentinelAlertRuleFusion_disable
=== RUN   TestAccSentinelAlertRuleFusion_sourceSetting
=== PAUSE TestAccSentinelAlertRuleFusion_sourceSetting
=== CONT  TestAccSentinelAlertRuleFusion_basic
=== CONT  TestAccSentinelAlertRuleFusion_sourceSetting
=== CONT  TestAccSentinelAlertRuleFusion_disable
--- PASS: TestAccSentinelAlertRuleFusion_basic (227.66s)
--- PASS: TestAccSentinelAlertRuleFusion_sourceSetting (263.98s)
--- PASS: TestAccSentinelAlertRuleFusion_disable (412.58s)
PASS
ok  	github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel	412.666s

5.0

❯❯ ARM_FIVEPOINTZERO_BETA=true tftest sentinel TestAccSentinelAlertRuleFusion_
=== RUN   TestAccSentinelAlertRuleFusion_basic
=== PAUSE TestAccSentinelAlertRuleFusion_basic
=== RUN   TestAccSentinelAlertRuleFusion_disable
=== PAUSE TestAccSentinelAlertRuleFusion_disable
=== RUN   TestAccSentinelAlertRuleFusion_sourceSetting
=== PAUSE TestAccSentinelAlertRuleFusion_sourceSetting
=== CONT  TestAccSentinelAlertRuleFusion_basic
=== CONT  TestAccSentinelAlertRuleFusion_sourceSetting
=== CONT  TestAccSentinelAlertRuleFusion_disable
--- PASS: TestAccSentinelAlertRuleFusion_basic (433.09s)
--- PASS: TestAccSentinelAlertRuleFusion_sourceSetting (508.14s)
--- PASS: TestAccSentinelAlertRuleFusion_disable (828.12s)
PASS
ok  	github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel	828.202s

Comment on lines 75 to 78
### `azurerm_sentinel_alert_rule_fusion`

* The deprecated `name` property has been removed.

Copy link
Member

Choose a reason for hiding this comment

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

As specified in point 4 for breaking schema changes these should be listed in alphabetical order, so should be put before all the storage changes above


resp, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("retrieving %q: %+v", id, err)
Copy link
Member

Choose a reason for hiding this comment

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

Hasn't been updated

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

Thanks @ziyeqf LGTM 🦖

@stephybun stephybun merged commit b70594c into hashicorp:main Nov 7, 2024
32 checks passed
@github-actions github-actions bot added this to the v4.9.0 milestone Nov 7, 2024
@ziyeqf ziyeqf deleted the sentinel_fusion_exisiting branch November 8, 2024 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants