-
Notifications
You must be signed in to change notification settings - Fork 389
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
[security_monitoring_default_rule] Fix acceptance tests for default rules #1707
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
datadog/tests/cassettes/TestAccDatadogSecurityMonitoringDefaultRule_Basic.freeze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2022-10-13T14:12:00.249128+02:00 | ||
2023-01-09T11:33:37.933584+01:00 |
315 changes: 57 additions & 258 deletions
315
datadog/tests/cassettes/TestAccDatadogSecurityMonitoringDefaultRule_Basic.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,20 +18,22 @@ func TestAccDatadogSecurityMonitoringDefaultRule_Basic(t *testing.T) { | |
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: accProviders, | ||
Steps: []resource.TestStep{ | ||
// Define an existing default rule as one we want to import | ||
{ | ||
Config: testAccCheckDatadogSecurityMonitoringDefaultDatasource(), | ||
Config: testAccDatadogSecurityMonitoringDefaultDatasource(), | ||
}, | ||
// Import the rule | ||
{ | ||
Config: testAccCheckDatadogSecurityMonitoringDefaultNoop(), | ||
ResourceName: tfSecurityDefaultRuleName, | ||
ImportState: true, | ||
ImportStateIdFunc: idFromDatasource, | ||
Config: testAccCheckDatadogSecurityMonitoringDefaultNoop(), | ||
ResourceName: tfSecurityDefaultRuleName, | ||
ImportState: true, | ||
ImportStateIdFunc: idFromDatasource, | ||
ImportStatePersist: true, | ||
}, | ||
// Change the "decrease criticality" flag | ||
{ | ||
Config: testAccCheckDatadogSecurityMonitoringDefaultDynamicCriticality(), | ||
ResourceName: tfSecurityDefaultRuleName, | ||
ImportState: true, | ||
ImportStateIdFunc: idFromDatasource, | ||
Config: testAccDatadogSecurityMonitoringDefaultRuleDynamicCriticality(), | ||
Check: testAccCheckDatadogSecurityMonitoringDefaultDynamicCriticality(), | ||
}, | ||
}, | ||
}) | ||
|
@@ -43,26 +45,28 @@ func idFromDatasource(state *terraform.State) (string, error) { | |
return resourceState.Primary.Attributes["rule_ids.0"], nil | ||
} | ||
|
||
func testAccCheckDatadogSecurityMonitoringDefaultDatasource() string { | ||
func testAccDatadogSecurityMonitoringDefaultDatasource() string { | ||
return ` | ||
data "datadog_security_monitoring_rules" "bruteforce" { | ||
name_filter = "docker" | ||
tags_filter = ["source:cloudtrail"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sure we're importing a default rule of type log detection. CloudTrail rules should all be of type log detection. The previous filter returned an infrastructure configuration rule. |
||
default_only_filter = "true" | ||
} | ||
` | ||
} | ||
|
||
func testAccCheckDatadogSecurityMonitoringDefaultNoop() string { | ||
return ` | ||
data "datadog_security_monitoring_rules" "bruteforce" { | ||
name_filter = "docker" | ||
tags_filter = ["source:cloudtrail"] | ||
default_only_filter = "true" | ||
} | ||
|
||
resource "datadog_security_monitoring_default_rule" "acceptance_test" { | ||
} | ||
` | ||
} | ||
|
||
func testAccCheckDatadogSecurityMonitoringDefaultDynamicCriticality() string { | ||
func testAccDatadogSecurityMonitoringDefaultRuleDynamicCriticality() string { | ||
return ` | ||
resource "datadog_security_monitoring_default_rule" "acceptance_test" { | ||
options { | ||
|
@@ -72,7 +76,7 @@ resource "datadog_security_monitoring_default_rule" "acceptance_test" { | |
` | ||
} | ||
|
||
func testAccCheckDatadogSecurityMonitoringDefaultDynamicCriticalityCheck() resource.TestCheckFunc { | ||
func testAccCheckDatadogSecurityMonitoringDefaultDynamicCriticality() resource.TestCheckFunc { | ||
return resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
tfSecurityDefaultRuleName, "options.0.decrease_criticality_based_on_env", "true"), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to persist the state so that we can access it in the next step. No checks are run if we're importing a state in a test step.